help update my datagrid to the database

tanya2001

New member
Joined
Oct 18, 2007
Messages
4
Programming Experience
Beginner
hi all below given is the code which i have given for my asp.net application i have to update my datagrid to the database the given below cpde is updating the flag value but not the other 2 fields...its just taking a blank value but not the one which i entered in the datagrid while editing...can somebody plz help me check with the code m giving both .net as well as html code..somebody plzz help e iout in this...i need help urgently..you can even email me on urs_forever_tanya2001@yahoo.co.in



Protected Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim Stocksent1 As TextBox = CType(e.Item.FindControl("TextBox2"), TextBox)

Dim Signed1 As TextBox = CType(e.Item.FindControl("SignedTextBox"), TextBox)
Dim Items As Integer = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()

Dim myConnection As New SqlConnection("Server=;uid=sa;pwd=;Database=")
myConnection.Open()

myCommand1 = New SqlCommand("Update Table3 set Stocksent=@Stocksent1, Signedby=@Signedby1 , Flag=0 where Items=@Items", myConnection)
myCommand1.Parameters.Add("@Items", SqlDbType.Int).Value = Items

myCommand1.Parameters.Add("@Stocksent1", SqlDbType.NVarChar).Value = Stocksent1.Text

myCommand1.Parameters.Add("@Stocksent1", SqlDbType.NVarChar).Value = Signed1.Text

ra = myCommand1.ExecuteNonQuery()

myConnection.Close()

Response.Write("Items saved")

End Sub



HTML CODE

'>'>'>' NAME="Label1"><asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 88px; POSITION: absolute; TOP: 176px"
runat="server" Width="880px" DataKeyField="Items" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Lognumm" ReadOnly="True" HeaderText="Lognumm"></asp:BoundColumn>
<asp:BoundColumn DataField="Requestdate" ReadOnly="True" HeaderText="Requestdate"></asp:BoundColumn>
<asp:BoundColumn DataField="Hospital" ReadOnly="True" HeaderText="Hospital"></asp:BoundColumn>
<asp:BoundColumn DataField="Items" ReadOnly="True" HeaderText="Items"></asp:BoundColumn>
<asp:BoundColumn DataField="Currentstock" ReadOnly="True" HeaderText="Currentstock"></asp:BoundColumn>
<asp:BoundColumn DataField="Stockrequest" ReadOnly="True" HeaderText="Stockrequest"></asp:BoundColumn>
<asp:BoundColumn DataField="Priority" ReadOnly="True" HeaderText="Priority"></asp:BoundColumn>
<asp:BoundColumn DataField="Comment" ReadOnly="True" HeaderText="Comment"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Stocksent">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval (Container.DataItem , "Stocksent") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem , "Stocksent") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn HeaderText="Signedby">
<edititemtemplate>
<asp:TextBox runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.Signedby") %>' ID="SignedTextBox"></asp:TextBox>
</edititemtemplate>
<itemtemplate>
<asp:Label runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.Signedby") %>'></asp:Label>
</itemtemplate>
</asp:templatecolumn>
<asp:BoundColumn Visible="False" DataField="Takenby" HeaderText="Takenby"></asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="Comments" HeaderText="Comment"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Edit">
<ItemTemplate>
<asp:LinkButton runat="server" CausesValidation="false" CommandName="Edit" Text="Edit" ID="Linkbutton1"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton runat="server" CommandName="Update" Text="Update" ID="Linkbutton2"></asp:LinkButton>
<asp:LinkButton runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel" ID="Linkbutton3"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
 
Back
Top