![VB.NET源码-156个实用实例哦……](http://www.zhzx123.com/VB.NET_03.gif)
我用VB.NET和SQL SERVER2000做的这个管理系统,直接把SqlDataAdapter控件拖到一个页面,然后设置了数据源.以下是部分代码,也是这里出现问题的,请高人指点,万分感谢!
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim inRoeIndex As Integer
Dim strBuildingName, strBuildingLocate, strSquareArea, strHouseNumber, strConstArea, strContainArea, strGreenArea, strDevelopDate, strRemark As String
inRoeIndex = e.Item.ItemIndex()
strBuildingName = DirectCast(DataGrid1.Items(inRoeIndex).Cells(0).Controls(0), TextBox).Text
strBuildingLocate = DirectCast(DataGrid1.Items(inRoeIndex).Cells(1).Controls(0), TextBox).Text
strSquareArea = DirectCast(DataGrid1.Items(inRoeIndex).Cells(2).Controls(0), TextBox).Text
strHouseNumber = DirectCast(DataGrid1.Items(inRoeIndex).Cells(3).Controls(0), TextBox).Text
strConstArea = DirectCast(DataGrid1.Items(inRoeIndex).Cells(4).Controls(0), TextBox).Text
strContainArea = DirectCast(DataGrid1.Items(inRoeIndex).Cells(5).Controls(0), TextBox).Text
strGreenArea = DirectCast(DataGrid1.Items(inRoeIndex).Cells(6).Controls(0), TextBox).Text
strDevelopDate = DirectCast(DataGrid1.Items(inRoeIndex).Cells(7).Controls(0), TextBox).Text
strRemark = DirectCast(DataGrid1.Items(inRoeIndex).Cells(8).Controls(0), TextBox).Text
Dim objConnection As SqlConnection
Dim myCommand As SqlCommand
Dim myDataAdapter As SqlDataAdapter
Dim myDataset As New DataSet
Dim strConnection As String
strConnection = workstation id=DUKE;packet size=4096;user id=sa;initial catalog=house;persist security info=False
objConnection = New SqlConnection(strConnection)
myCommand = New SqlCommand( update buildinginfo set buildinglocate= + strBuildingLocate + where buildingname= + strBuildingName + )
Try
objConnection.Open()
myCommand.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex.Message)
End Try
objConnection.Close()
myCommand = Nothing
End Sub
我把编辑,删除的按钮也添加到了DATAGRID中,不过在点更新以后,只有buildinglocate能够更新到数据库中,UPDATE的SQL语句我不会写,所以这里SQL语句提供的代码不完整,请问怎么能够实现对一条记录的每个字段都更新?UPDATE语句该怎么写?
__________________________________________________________________________
写SQL语句不就都更新了吗 myCommand=New SqlCommand( update buildinginfo set buildinglocate= & strBuildingLocate & ,buildingname= & strBuildingName & .... where ...... ) 不知我理解的对不对
__________________________________________________________________________
用update语句
__________________________________________________________________________
看了很多,都晕了,学习中。
__________________________________________________________________________