Hi,
I've brought a table from SQL Server into a Datagrid using VB.NET and have changed all fields to textboxes so I can edit any field and only save once. Everything works fine except the save button. I tried to use stored procedures but this is almost working. I've been working on this for a long time and I still need some help. If anyone could give me some idea it will be greatly appreciated. Here is my function:[code=vb]
Private Sub doSave(ByVal sender As Object, ByVal e As System.EventArg s)
Dim myCommand As SqlCommand
Dim dstCopy As New DataSet
Dim strQuery As String
objConnection = New SqlConnection(" server=SQLSERVE R;database=upsi zedCandidate;In tegrated Security=True;" )
objConnection.O pen()
Dim dgItem As DataGridItem
For Each dgItem In myInfo.Items
Dim txtmyNewCol1 As TextBox = _
CType(dgItem.Ce lls(0).FindCont rol("txtmyNewCo l1"), TextBox)
Dim txtmyNewCol2 As TextBox = _
CType(dgItem.Ce lls(1).FindCont rol("txtmynewCo l2"), TextBox)
strQuery = String.Format(" update ToddsTable1 set myNewCol1= '" + txtmyNewCol1.Te xt + "',myNewCol 2='" + txtmyNewCol2.Te xt + "'")
myCommand = New SqlCommand(strQ uery, objConnection)
myCommand.Execu teNonQuery()
Next
Page.DataBind()
myInfo.DataBind ()
objConnection.C lose()
myInfo.EditItem Index = -1
ShowDataGrid()
End Sub
----------------------------------------------------------------
Here is the button that fires it:
<asp:TemplateCo lumn HeaderText="Sav e">
<FooterTemplate >
<asp:Button CommandName="Sa ve" Text="Save" ID="btnSave" OnClick="doSave " runat="server" />
</FooterTemplate>
</asp:TemplateCol umn>
[/code]
Please help!!
I've brought a table from SQL Server into a Datagrid using VB.NET and have changed all fields to textboxes so I can edit any field and only save once. Everything works fine except the save button. I tried to use stored procedures but this is almost working. I've been working on this for a long time and I still need some help. If anyone could give me some idea it will be greatly appreciated. Here is my function:[code=vb]
Private Sub doSave(ByVal sender As Object, ByVal e As System.EventArg s)
Dim myCommand As SqlCommand
Dim dstCopy As New DataSet
Dim strQuery As String
objConnection = New SqlConnection(" server=SQLSERVE R;database=upsi zedCandidate;In tegrated Security=True;" )
objConnection.O pen()
Dim dgItem As DataGridItem
For Each dgItem In myInfo.Items
Dim txtmyNewCol1 As TextBox = _
CType(dgItem.Ce lls(0).FindCont rol("txtmyNewCo l1"), TextBox)
Dim txtmyNewCol2 As TextBox = _
CType(dgItem.Ce lls(1).FindCont rol("txtmynewCo l2"), TextBox)
strQuery = String.Format(" update ToddsTable1 set myNewCol1= '" + txtmyNewCol1.Te xt + "',myNewCol 2='" + txtmyNewCol2.Te xt + "'")
myCommand = New SqlCommand(strQ uery, objConnection)
myCommand.Execu teNonQuery()
Next
Page.DataBind()
myInfo.DataBind ()
objConnection.C lose()
myInfo.EditItem Index = -1
ShowDataGrid()
End Sub
----------------------------------------------------------------
Here is the button that fires it:
<asp:TemplateCo lumn HeaderText="Sav e">
<FooterTemplate >
<asp:Button CommandName="Sa ve" Text="Save" ID="btnSave" OnClick="doSave " runat="server" />
</FooterTemplate>
</asp:TemplateCol umn>
[/code]
Please help!!
Comment