I'm trying to do the right thing by using stored procs but i'm really leaning toward ad-hoc if I can't figure this out. I've been working on this for two days now and I'm getting no where.
In short the page is loaded with ONE line in a datagrid with a button to order. The page load works great, it populates the cells and I'm tickled about that. Now I want to send the data back to the database.
Please help me wrap this up today. I'd like to end my work week on a plus.
ASP Side:
<aspataGrid ID="orderdatagrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateColumn HeaderText="Partnumber">
<ItemTemplate>
<asp:Label ID="lblPartNumber" runat="server" text='<%#(databinder.eval(container.dataitem, "partnumber" ).ToString()) %>' />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Actual Count">
<ItemTemplate>
<asp:Label ID="lblActual" runat="server" text='<%#(databinder.eval(container.dataitem, "actual" ).ToString()) %>' />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Order Point">
<ItemTemplate>
<asp:Label ID="lblOrderPoint" runat="server" text='<%#(databinder.eval(container.dataitem, "orderpoint" ).ToString()) %>' />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Order">
<ItemTemplate>
<asp:Button CommandName="Insert" Text="Order Now" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Order Quantity">
<ItemTemplate>
<asp:TextBox ID="txtQty" runat="server" Text='<%#(DataBinder.Eval(Container.DataItem, "actual" ).ToString())%>' />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
VB Side: (minus the page load)
Sub Insert_Record(ByVal src As Object, ByVal args As DataGridCommandEventArgs)
KBCS.Open()
Dim PNOrder As Label = args.Item.FindControl("lblPartNumber")
Dim UName As String = Environment.UserName
Dim OrdQty As TextBox = args.Item.FindControl("txtQty")
Dim datenow As Date = Now
If args.CommandName = "Insert" Then
Dim SqlCmd As New SqlCommand("SPVSKB_ORDERNOW", KBCS)
SqlCmd.CommandType = CommandType.StoredProcedure
SqlCmd.Parameters.Add("@PartNumber", SqlDbType.VarChar).Value = PNOrder
SqlCmd.Parameters.Add("@Uname", SqlDbType.VarChar).Value = UName
SqlCmd.Parameters.Add("@QtyOrdered", SqlDbType.Int).Value = OrdQty
SqlCmd.Parameters.Add("@datenow", SqlDbType.DateTime).Value = datenow
SqlCmd.ExecuteNonQuery()
End If
KBCS.Close()
End Sub
In short the page is loaded with ONE line in a datagrid with a button to order. The page load works great, it populates the cells and I'm tickled about that. Now I want to send the data back to the database.
Please help me wrap this up today. I'd like to end my work week on a plus.
ASP Side:
<aspataGrid ID="orderdatagrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateColumn HeaderText="Partnumber">
<ItemTemplate>
<asp:Label ID="lblPartNumber" runat="server" text='<%#(databinder.eval(container.dataitem, "partnumber" ).ToString()) %>' />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Actual Count">
<ItemTemplate>
<asp:Label ID="lblActual" runat="server" text='<%#(databinder.eval(container.dataitem, "actual" ).ToString()) %>' />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Order Point">
<ItemTemplate>
<asp:Label ID="lblOrderPoint" runat="server" text='<%#(databinder.eval(container.dataitem, "orderpoint" ).ToString()) %>' />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Order">
<ItemTemplate>
<asp:Button CommandName="Insert" Text="Order Now" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Order Quantity">
<ItemTemplate>
<asp:TextBox ID="txtQty" runat="server" Text='<%#(DataBinder.Eval(Container.DataItem, "actual" ).ToString())%>' />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
VB Side: (minus the page load)
Sub Insert_Record(ByVal src As Object, ByVal args As DataGridCommandEventArgs)
KBCS.Open()
Dim PNOrder As Label = args.Item.FindControl("lblPartNumber")
Dim UName As String = Environment.UserName
Dim OrdQty As TextBox = args.Item.FindControl("txtQty")
Dim datenow As Date = Now
If args.CommandName = "Insert" Then
Dim SqlCmd As New SqlCommand("SPVSKB_ORDERNOW", KBCS)
SqlCmd.CommandType = CommandType.StoredProcedure
SqlCmd.Parameters.Add("@PartNumber", SqlDbType.VarChar).Value = PNOrder
SqlCmd.Parameters.Add("@Uname", SqlDbType.VarChar).Value = UName
SqlCmd.Parameters.Add("@QtyOrdered", SqlDbType.Int).Value = OrdQty
SqlCmd.Parameters.Add("@datenow", SqlDbType.DateTime).Value = datenow
SqlCmd.ExecuteNonQuery()
End If
KBCS.Close()
End Sub