Results 1 to 7 of 7

Thread: Noobie question

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2014
    Posts
    35

    Noobie question

    I fully admit to being a novice, and I know a lot of what I am asking is basic, but I am under a time crunch and could use some guidance. I have a web application that I am writing that collects information for insertion into a database table. A part of this is having the user fill out some information that is placed into a gridview control, and could be multiple rows in that gridview. I have no problem saving the data IF there is only one row in the gridview, but when I loop through the rows to save multiple row values, the SQL stored proc seems not to handle the rows beyond row 1. It returns the stored proc error of too many arguments. I feel certain this is due to one of 2 things: (1) the stored proc is looking for various values, and from the gridview it is collecting the row values, then executing the stored proc, and when multiple rows are populated, there are more values than the stored proc has or (2) being a novice, I am approaching this wrong from the get-go.
    My question is how to save these multiple row values to the database. The code to save follows:

    Code:
       Protected Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
            Dim conn As New SqlConnection("Data Source=server;Initial Catalog=database;User ID=user;Password=password")
            Dim cmd As New SqlCommand
            Dim County As String
            Dim UFTRS As String
            Dim Use As String
            Dim N As Int32
            Dim P As Int32
            Dim K As Int32
            Dim ToCo As String
            Dim uftrs1 As String
            Dim tons As Int32
    
    
            cmd.CommandText = "tempsave"
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = conn
            Try
                conn.Open()
                cmd.Parameters.Clear()
                cmd.Parameters.AddWithValue("@lnglicno", licno.SelectedValue)
                cmd.Parameters.AddWithValue("@dtrcvd", Date.Today)
                cmd.Parameters.AddWithValue("@intqtr", DDLQtr.SelectedValue)
                cmd.Parameters.AddWithValue("@intyear", DDLYr.SelectedValue)
                cmd.Parameters.AddWithValue("@amount", Txtpayment.Text)
                cmd.Parameters.AddWithValue("@tonfees", (totTon.Text * 0.25))
                cmd.Parameters.AddWithValue("@penalty", ((totTon.Text * 0.25) * 0.1))
                For Each row As GridViewRow In GridView2.Rows
                    For i As Integer = 0 To GridView2.Rows.Count - 1
                        County = GridView2.Rows(i).Cells(1).Text
                        UFTRS = GridView2.Rows(i).Cells(2).Text
                        tons = GridView2.Rows(i).Cells(4).Text
                        Use = GridView2.Rows(i).Cells(5).Text
                        N = GridView2.Rows(i).Cells(6).Text
                        P = GridView2.Rows(i).Cells(7).Text
                        K = GridView2.Rows(i).Cells(8).Text
                        cmd.Parameters.AddWithValue("@intcounty", County)
                        cmd.Parameters.AddWithValue("@dblton", totTon.Text)
                        If GridView2.Rows(i).Cells(3).Text = "Bag" Then
                            cmd.Parameters.AddWithValue("@inttontype", "1")
                        ElseIf GridView2.Rows(i).Cells(3).Text = "Bulk" Then
                            cmd.Parameters.AddWithValue("@inttontype", "2")
                        ElseIf GridView2.Rows(i).Cells(3).Text = "Liq" Then
                            cmd.Parameters.AddWithValue("@inttontype", "3")
                        End If
    
                        cmd.Parameters.AddWithValue("@intuse", Use)
                        cmd.Parameters.AddWithValue("@dtproc", Date.Today)
                        cmd.Parameters.AddWithValue("@uftrs", UFTRS)
                        cmd.Parameters.AddWithValue("@dblN", N)
                        cmd.Parameters.AddWithValue("@dblP", P)
                        cmd.Parameters.AddWithValue("@dblK", K)
                        cmd.Parameters.AddWithValue("@dtDateTime", Date.Today)
                    Next
                    If Chk1.Checked Then
                        For Each row1 As GridViewRow In GridView1.Rows
                            For x As Integer = 0 To GridView1.Rows.Count - 1
                                ToCo = GridView1.Rows(x).Cells(1).Text
                                uftrs1 = GridView1.Rows(x).Cells(3).Text
                                cmd.Parameters.AddWithValue("@toco", ToCo)
                                cmd.Parameters.AddWithValue("@dbltontotal", potons.Text)
                                If GridView1.Rows(x).Cells(4).Text = "Bag" Then
                                    cmd.Parameters.AddWithValue("@inttontype1", "1")
                                ElseIf GridView1.Rows(x).Cells(5).Text = "Bulk" Then
                                    cmd.Parameters.AddWithValue("@inttontype1", "2")
                                ElseIf GridView1.Rows(x).Cells(6).Text = "Liquid" Then
                                    cmd.Parameters.AddWithValue("@inttontype1", "3")
                                End If
                                cmd.Parameters.AddWithValue("@intcode1", uftrs1)
                            Next
                        Next
                    End If
                Next
                    cmd.ExecuteNonQuery()
            Finally
                conn.Close()
            End Try
    End Sub
    The stored proc is a simple insert statement using the variables indicated in the code above.

    Any help available?

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Noobie question

    Ok... you're using Parameters which is EXCELLENT (you don't know how many people I have to tutor on SQL injection hacks).

    I think the problem is you're using them with "AddWithValue" which is great if you got one command you're firing off to a database, but not great if you want to send a whole bunch with different values.

    Here's a quick example of a loop that sends 10 INSERT statements to a database:
    Code:
            Using conn As New SqlConnection("Data Source=server;Initial Catalog=database;User ID=user;Password=password")
                'Insert 10 items into a database using a single SQL command and parameters
                conn.Open()
                Dim strSQL As String = "INSERT INTO table (name, number) VALUES(@name, @number);"
    
                Dim cmd As New SqlCommand(strSQL, conn)
                cmd.Parameters.Add("@name", SqlDbType.VarChar, 30)
                cmd.Parameters.Add("@number", SqlDbType.Int)
    
                Dim names() As String = {"Amber", "Bob", "Charles", "Danielle", "Edward", "Fiona", "Gary", "Helen", "Ivan", "Julie"}
                Dim numbers() As Integer = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}
    
                For i As Integer = 0 To 9
                    cmd.Parameters("@name").Value = names(i)
                    cmd.Parameters("@number").Value = numbers(i)
                    cmd.ExecuteNonQuery()
                Next
                conn.Close()
            End Using
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2014
    Posts
    35

    Re: Noobie question

    Jennifer - Thanks for the pointers. I have made some adjustments, and perhaps I am not understanding, but I am now getting errors that @intcounty variable has already been declared and must declare scalar variable @toco. Also, in the original code, I am doing some math calculations. Now sure how these will be done under the current scenario.
    Current code:
    Code:
      Protected Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
    
            'Dim cmd As New SqlCommand
            Dim County As String
            Dim UFTRS As String = DDLCode1.SelectedValue
            Dim Use As String = DDLUse1.SelectedValue
            Dim N As Int32 = txtN1.Text
            Dim P As Int32 = txtP1.Text
            Dim K As Int32 = txtK1.Text
            Dim ToCo As String = DDLConum.SelectedValue
            Dim uftrs1 As String = DDLCode2.SelectedValue
            Dim tons As Int32
    
    
            Using conn As New SqlConnection("Data Source=azda-sql0;Initial Catalog=fertilizersql;User ID=sa;Password=Sql@dm!n")
                Dim strSQL As String = "Insert into savetemp (lnglicno, dtrcvd, intqtr, intyear, intcounty, uftrs, dblton, inttontype, intuse, dtproc, dbln, dblp, dblk, dtdatetime, toco, intcode1, dbltontotal, inttontype1, amount, tonfees, penalty) values (@lnglicno, @dtrcvd, @intqtr, @intyear, @intcounty, @uftrs, @dblton, @inttontype, @intuse, @dtproc, @dbln, @dblp, @dblk, @dtdatetime, @toco, @intcode1, @dbltontotal, @inttontype1, @amount, @tonfees, @penalty)"
                Dim cmd As New SqlCommand(strSQL, conn)
    
                'cmd.CommandText = "tempsave"
                'cmd.CommandType = CommandType.StoredProcedure
                'cmd.Connection = conn
                Try
                    conn.Open()
                    cmd.Parameters.Clear()
                    cmd.Parameters.Add("@lnglicno", SqlDbType.Int)
                    cmd.Parameters.Add("@dtrcvd", SqlDbType.Date)
                    cmd.Parameters.Add("@intqtr", SqlDbType.Int)
                    cmd.Parameters.Add("@intyear", SqlDbType.Int)
                    cmd.Parameters.Add("@amount", SqlDbType.Money)
                    cmd.Parameters.Add("@tonfees", SqlDbType.Money)
                    '= totTon.Text * 0.25
                    cmd.Parameters.Add("@penalty", SqlDbType.Money)
                    '((totTon.Text * 0.25) * 0.1))
                    For Each row As GridViewRow In GridView2.Rows
                        For i As Integer = 0 To GridView2.Rows.Count - 1
                            County = GridView2.Rows(i).Cells(1).Text
                            UFTRS = GridView2.Rows(i).Cells(2).Text
                            tons = GridView2.Rows(i).Cells(4).Text
                            Use = GridView2.Rows(i).Cells(5).Text
                            N = GridView2.Rows(i).Cells(6).Text
                            P = GridView2.Rows(i).Cells(7).Text
                            K = GridView2.Rows(i).Cells(8).Text
                            cmd.Parameters.Add("@intcounty", SqlDbType.NVarChar, 50)
                            cmd.Parameters.Add("@dblton", SqlDbType.Int)
                            If GridView2.Rows(i).Cells(3).Text = "Bag" Then
                                cmd.Parameters.AddWithValue("@inttontype", "1")
                            ElseIf GridView2.Rows(i).Cells(3).Text = "Bulk" Then
                                cmd.Parameters.AddWithValue("@inttontype", "2")
                            ElseIf GridView2.Rows(i).Cells(3).Text = "Liq" Then
                                cmd.Parameters.AddWithValue("@inttontype", "3")
                            End If
    
                            cmd.Parameters.Add("@intuse", SqlDbType.SmallInt)
                            cmd.Parameters.Add("@dtproc", SqlDbType.Date)
                            cmd.Parameters.Add("@uftrs", SqlDbType.SmallInt)
                            cmd.Parameters.Add("@dblN", SqlDbType.Int)
                            cmd.Parameters.Add("@dblP", SqlDbType.Int)
                            cmd.Parameters.Add("@dblK", SqlDbType.Int)
                            cmd.Parameters.Add("@dtDateTime", SqlDbType.Date)
                        Next
                        If Chk1.Checked Then
                            For Each row1 As GridViewRow In GridView1.Rows
                                For x As Integer = 0 To GridView1.Rows.Count - 1
                                    ToCo = GridView1.Rows(x).Cells(1).Text
                                    uftrs1 = GridView1.Rows(x).Cells(3).Text
                                    cmd.Parameters.Add("@toco", SqlDbType.Int)
                                    cmd.Parameters.Add("@dbltontotal", SqlDbType.Int)
                                    If GridView1.Rows(x).Cells(4).Text = "Bag" Then
                                        cmd.Parameters.AddWithValue("@inttontype1", "1")
                                    ElseIf GridView1.Rows(x).Cells(5).Text = "Bulk" Then
                                        cmd.Parameters.AddWithValue("@inttontype1", "2")
                                    ElseIf GridView1.Rows(x).Cells(6).Text = "Liquid" Then
                                        cmd.Parameters.AddWithValue("@inttontype1", "3")
                                    End If
                                    cmd.Parameters.Add("@intcode1", SqlDbType.SmallInt)
                                Next
                            Next
                        End If
                    Next
                Finally
                End Try
                cmd.ExecuteNonQuery()
    
                conn.Close()
            End Using
    End Sub

  4. #4
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Noobie question

    Yea, @intcounty variable has already been declared and your problems are because you got them INSIDE your loop, and you're not setting the VALUES anywhere.

    Honestly, your code makes absolutely no sense to me. I copied it into an editor and I tried to follow it... you're looping through GridView2m then for every row you hit, you loop through GridView2 completely again... so if you got 10 things in GridView2, you'll have 100 things in your database... and then you got GridView1 that you're looping through, and I don't know why, because only the last value is going to be recorded in the database... and you got that looping twice, and as many times as GridView2 so once again, with 10 things in GridView 1 and 10 things in GridView2, 1000 times there.

    What EXACTLY are you trying to do? Post up a screenshot of your Form with some data in it so I can make sense of your intent so I can figure this out.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2014
    Posts
    35

    Re: Noobie question

    Thanks again, and I understand your confusion. The web form follows. Basically there are 2 gridviews, that could contain multiple rows of data.

    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" MaintainScrollPositionOnPostback="true" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Fertilizer Tonnage Reporting</title>
        <style type="text/css">
            .auto-style1 {
                font-size: x-large;
            }
            .auto-style2 {
                font-size: small;
            }
            .auto-style3 {
                font-size: large;
            }
        </style>
    </head>
    <body id="PageBody" runat="server">
        <form id="form1" runat="server">
        <div>
        <center style="font-weight: 700"><strong><span class="auto-style1">Quarterly Tonnage Reporting<br />
            </span></strong><br />
            Type your license number: <asp:DropDownList ID="licno" runat="server" DataSourceID="SqlDataSource4" DataTextField="lngLicNum" DataValueField="lngLicNum" AutoPostBack="true" AppendDataBoundItems="true" OnSelectedIndexChanged="licno_SelectedIndexChanged"><asp:ListItem Selected="True"></asp:ListItem></asp:DropDownList>  
            <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:FertilizerSQLConnectionString %>" SelectCommand="SELECT [lngLicNum] FROM [tblFertLic] WHERE [dtexpiration] > getdate() ORDER BY [lngLicNum]"></asp:SqlDataSource>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="licno" Display="Dynamic" ErrorMessage="Must Choose a license number" ForeColor="Red"></asp:RequiredFieldValidator>
    <br />
    <asp:Label ID="Coname" runat="server"></asp:Label><br />
    <asp:Label ID="Coaddr" runat="server"></asp:Label><br />
    <asp:Label ID="coaddr1" runat="server"></asp:Label><br />
    <asp:Label ID="ctystzip" runat="server"></asp:Label>
            <br />
            <br />
            This submission is for Quarter <asp:DropDownList ID="DDLQtr" runat="server">
                <asp:ListItem Selected="True" />
                <asp:ListItem Text="1" Value="1"/>
                <asp:ListItem Text="2" Value="2"/>
                <asp:ListItem Text="3" Value="3"/>
                <asp:ListItem Text="4" Value="4"/>
                                           </asp:DropDownList>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DDLQtr" Display="Dynamic" InitialValue="Choose" ErrorMessage="Must choose a Quarter" ForeColor="Red"></asp:RequiredFieldValidator>
            &nbsp;&nbsp;
            This submission is for year <asp:DropDownList ID="DDLYr" runat="server" AppendDataBoundItems="true" AutoPostBack="true"><asp:ListItem Selected="True"></asp:ListItem></asp:DropDownList><br /><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="DDLYr" Display="Dynamic" InitialValue="Choose" ErrorMessage="Must choose a year" ForeColor="Red"></asp:RequiredFieldValidator>
            Pass-Ons to your company from others<br />
            <span class="auto-style2">If you disagree with pass-ons, you must contact the referring company to resolve before payment can be accepted<br />
            </span>
            <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource5" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">
                <AlternatingRowStyle BackColor="#DCDCDC" />
                <Columns>
                    <asp:BoundField DataField="dtRcvd" HeaderText="Date Rcvd" DataFormatString="{0:d}" SortExpression="dtRcvd" />
                    <asp:BoundField DataField="intYear" HeaderText="Year" SortExpression="intYear" />
                    <asp:BoundField DataField="intQtr" HeaderText="Qtr" SortExpression="intQtr" />
                    <asp:BoundField DataField="lngLicNumFromCo" HeaderText="From Co" SortExpression="lngLicNumFromCo" />
                    <asp:BoundField DataField="txtCoName" HeaderText="From Co Name" SortExpression="txtFromName" />
                    <asp:BoundField DataField="intTonType" HeaderText="Ton Type" SortExpression="intTonType" />
                    <asp:BoundField DataField="intCode" HeaderText="Code" SortExpression="intCode" />
                    <asp:BoundField DataField="dblTonTotal" HeaderText="Ton Total" SortExpression="dblTonTotal" />
                </Columns>
                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#F1F1F1" />
                <SortedAscendingHeaderStyle BackColor="#0000A9" />
                <SortedDescendingCellStyle BackColor="#CAC9C9" />
                <SortedDescendingHeaderStyle BackColor="#000065" />
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:FertilizerSQLConnectionString %>" SelectCommand="SELECT [dtRcvd], [intYear], [intQtr], [lngLicNumFromCo], [txtCoName], [intTonType], [intCode], round([dblTonTotal],0) as dbltontotal FROM [PassOnsTo] WHERE (([lngLicNumToCo] = @lngLicNumToCo) AND ([intQtr] = @intQtr) AND ([intyear] = @intyear))">
                <SelectParameters>
                    <asp:ControlParameter ControlID="licno" Name="lngLicNumToCo" PropertyName="SelectedValue"/>
                    <asp:ControlParameter ControlID="DDLQtr" Name="intQtr" PropertyName="SelectedValue"/>
                    <asp:ControlParameter ControlID="DDLYr" Name ="intYear" PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>
            <br />
            <br />
          Pass-On Tons: <asp:TextBox ID="tontot" runat="server" Visible="True" DataFormatString="{#,###}" Width="87px"></asp:TextBox>
            <br />
            <hr />
            <br />
            
            <hr />
            Tonnage entry - enter whole tons only (no decimals)
    <asp:Table ID="Table1" runat="server" BorderStyle="Groove" GridLines="Both">
        <asp:TableHeaderRow><asp:TableHeaderCell Text="County"></asp:TableHeaderCell>
            <asp:TableHeaderCell Text="UFTRS Fertilizer Code"></asp:TableHeaderCell>
            <asp:TableHeaderCell Text="Ton Type"></asp:TableHeaderCell>
            <asp:TableHeaderCell Text="Tons"></asp:TableHeaderCell>
            <asp:TableHeaderCell Text="Use"></asp:TableHeaderCell>
            <asp:TableHeaderCell Text="Grade"></asp:TableHeaderCell>
            <asp:TableHeaderCell Text="Product"></asp:TableHeaderCell>
        </asp:TableHeaderRow>
        <asp:TableRow>
            <asp:TableCell><asp:DropDownList ID="DDLCty1" runat="server" DataSourceID="SqlDataSource1" DataTextField="txtCounty" DataValueField="txtCounty" AppendDataBoundItems="true"><asp:ListItem Text="Choose"></asp:ListItem></asp:DropDownList></asp:TableCell>
            <asp:TableCell HorizontalAlign="Center"><asp:DropDownList ID="DDLCode1" runat="server" DataSourceID="SqlDataSource2" AutoPostBack="true" DataTextField="intcode" OnSelectedIndexChanged="DDLCode1_SelectedIndexChanged" DataVauleField="intcode" AppendDataBoundItems="true"><asp:ListItem Text="Choose"></asp:ListItem></asp:DropDownList></asp:TableCell>
            <asp:TableCell><asp:DropDownList ID="TonType" runat="server"><asp:ListItem>Bag</asp:ListItem><asp:ListItem>Bulk</asp:ListItem><asp:ListItem>Liquid</asp:ListItem></asp:DropDownList></asp:TableCell>
            <asp:TableCell><asp:TextBox ID="totaltons" runat="server"></asp:TextBox></asp:TableCell>
            <asp:TableCell><asp:DropDownList ID="DDLUse1" runat="server" AppendDataBoundItems="true"><asp:ListItem Text="Choose" Selected="True"></asp:ListItem><asp:ListItem Text="Ag Use" Value="1"></asp:ListItem><asp:ListItem Text="Non-Ag" Value="2"></asp:ListItem></asp:DropDownList></asp:TableCell>
            <asp:TableCell>N: <asp:TextBox ID="txtN1" runat="server" Width="50"/> P: <asp:TextBox ID="txtP1" runat="server" Width="50"/> K: <asp:TextBox ID="txtK1" runat="server" Width="50"/></asp:TableCell><asp:TableCell><asp:TextBox ID="txtprod" runat="server" Width="300"></asp:TextBox></asp:TableCell></asp:TableRow></asp:Table><br />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="txtN1" ErrorMessage="Maximum 2 decimals" ValidationExpression="^[0-9]+(\.[0-9]{1,2})?$" Display="Dynamic" ForeColor="Red"></asp:RegularExpressionValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ControlToValidate="txtP1" ErrorMessage="Maximum 2 decimals" ValidationExpression="^[0-9]+(\.[0-9]{1,2})?$" Display="Dynamic" ForeColor="Red"></asp:RegularExpressionValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" ControlToValidate="txtK1" ErrorMessage="Maximum 2 decimals" ValidationExpression="^[0-9]+(\.[0-9]{1,2})?$" Display="Dynamic" ForeColor="Red"></asp:RegularExpressionValidator><asp:Button ID="BtnAdd" runat="server" Text="Add Product"></asp:Button>
            <br /><br /><asp:GridView ID="GridView2" runat="server" OnRowDeleting="OnRowDeleting" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="967px"><AlternatingRowStyle BackColor="#DCDCDC" /><FooterStyle BackColor="#CCCCCC" ForeColor="Black" /><HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /><PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /><RowStyle BackColor="#EEEEEE" ForeColor="Black" /><SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /><SortedAscendingCellStyle BackColor="#F1F1F1" /><SortedAscendingHeaderStyle BackColor="#0000A9" /><SortedDescendingCellStyle BackColor="#CAC9C9" /><SortedDescendingHeaderStyle BackColor="#000065" />
                <Columns>
                 <asp:CommandField ShowDeleteButton="true" ButtonType="Button" />
                    </Columns>
                              </asp:GridView>
    
            <br />Total Tons: <asp:TextBox ID="totTon" runat="server" Width="47px"></asp:TextBox><span class="auto-style2"><br /><br /><hr /></span><span class="auto-style1">Fees</span><span class="auto-style2"><br />Includes a 10% penalty ($10 minimum) if submitted more than one month after the quarter chosen above<br /><br />Total Fee Due <asp:TextBox ID="Txtpayment" runat="server" Text="$2.00" Width="160px" Font-Bold="True" Style="text-align: center"></asp:TextBox><br /><br /></span><span class="auto-style3">Pass-Ons</span><span class="auto-style2"><br /></span><br class="auto-style2" /><br />For tonnage that is being passed on to another company licensed in the State of Arizona, check here and complete below: : <asp:CheckBox ID="Chk1" runat="server" AutoPostBack="true"></asp:CheckBox><br /><br />
            <asp:Table ID="Table2" runat="server" GridLines="Both" Visible="false">
        <asp:TableHeaderRow><asp:TableHeaderCell Text="Company Number"></asp:TableHeaderCell><asp:TableHeaderCell Text="Company Name"></asp:TableHeaderCell><asp:TableHeaderCell Text="UFTRS Fertilizer Code"></asp:TableHeaderCell><asp:TableHeaderCell Text="Type"></asp:TableHeaderCell><asp:TableHeaderCell Text="Tons"></asp:TableHeaderCell><asp:TableHeaderCell Text="Grade"></asp:TableHeaderCell><asp:TableHeaderCell>Product</asp:TableHeaderCell></asp:TableHeaderRow><asp:TableRow>
            <asp:TableCell  HorizontalAlign="Center" ><asp:DropDownList ID="DDLConum" runat="server" AutoPostBack="True" OnSelectedIndexChanged="Conum_SelectedIndexChanged" DataSourceID="SqlDataSource3" DataTextField="lnglicnum" DataValueField="lnglicnum" AppendDataBoundItems="true"><asp:ListItem Text="Choose"></asp:ListItem></asp:DropDownList></asp:TableCell><asp:TableCell><asp:Label ID="Conamepo" runat="server" HorizontalAlign="Center" ></asp:Label></asp:TableCell><asp:TableCell HorizontalAlign="Center"><asp:DropDownList ID="DDLCode2" runat="server" DataSourceID="SqlDataSource2" DataTextField="intcode" AutoPostback="true" OnSelectedIndexChanged="DDLCode2_SelectedIndexChanged" DataVauleField="intcode" AppendDataBoundItems="true"><asp:ListItem Text="Choose"></asp:ListItem></asp:DropDownList></asp:TableCell><asp:TableCell><asp:DropDownList ID="ddlPOType" runat="server"><asp:ListItem>Bag</asp:ListItem><asp:ListItem>Bulk</asp:ListItem><asp:ListItem>Liquid</asp:ListItem></asp:DropDownList></asp:TableCell><asp:TableCell><asp:TextBox ID="potons" runat="server"></asp:TextBox></asp:TableCell><asp:TableCell>N: <asp:TextBox ID="txtN2" runat="server" Width="50"/> P: <asp:TextBox ID="txtP2" runat="server" Width="50"/> K: <asp:TextBox ID="txtK2" runat="server" Width="50"/></asp:TableCell><asp:TableCell><asp:TextBox ID="txtprod2" runat="server" Width="300"></asp:TextBox></asp:TableCell></asp:TableRow></asp:Table><br />
             <asp:Button ID="AddPO" runat="server" Text="Add PassOns" Visible="false"></asp:Button>
            <br /><br /><asp:GridView ID="GridView1" runat="server" OnRowDeleting="OnRowDeleting1" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="967px"><AlternatingRowStyle BackColor="Gainsboro" /><FooterStyle BackColor="#CCCCCC" ForeColor="Black" /><HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /><PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /><RowStyle BackColor="#EEEEEE" ForeColor="Black" /><SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /><SortedAscendingCellStyle BackColor="#F1F1F1" /><SortedAscendingHeaderStyle BackColor="#0000A9" /><SortedDescendingCellStyle BackColor="#CAC9C9" /><SortedDescendingHeaderStyle BackColor="#000065" />
                <Columns>
                 <asp:CommandField ShowDeleteButton="true" ButtonType="Button" />
                    </Columns>
                              </asp:GridView><br /><hr />
           
            <asp:Button ID="BtnSave" runat="server" Text="Process payment"></asp:Button>
           
    
          
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:FertilizerSQLConnectionString %>" SelectCommand="SELECT [txtCounty] FROM [tblCountyCodes] ORDER BY [txtCounty]"></asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:FertilizerSQLConnectionString %>" SelectCommand="SELECT [intcode] FROM tblUFTRSCodes ORDER BY [intcode]"></asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:FertilizerSQLConnectionString %>" SelectCommand="SELECT [lnglicnum] from tblfertlic where dtexpiration > getdate() order by lnglicnum"></asp:SqlDataSource>
        </div>
        </form>
    </body>
    </html>

  6. #6
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Noobie question

    Ok, and will these gridviews have the same number of rows each? If GridView1 has 10 rows, will GridView2 always have 10 rows?

    If they do, does the data in Gridview1.Row1 correspond to the data in Gridview2.Row1?

    If not, how is the data in Gridview2 related to the data in Gridview1?

    Are they related at all? Should this be something you should be using 2 tables for because you have 2 lists of data, rather than trying to combine them into 1 table?
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2014
    Posts
    35

    Re: Noobie question

    The gridviews contain different information, and not the same data in the gridviews. The number of rows can be different in each gridview. Like I said, I may be approaching the wrong from the get-go..

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width