[VB.NET]VB.NET做基于WEB的管理系统DATAGRID中数据修改的问题

本文探讨了使用VB.NET进行基于Web的管理系统开发时遇到的问题:如何在Datagrid控件中正确更新每条记录的所有字段。作者分享了部分代码,并寻求帮助以实现完整的数据更新功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

VB.NET源码-156个实用实例哦…… VB.NET做基于WEB的管理系统DATAGRID中数据修改的问题
我用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语句
__________________________________________________________________________
看了很多,都晕了,学习中。
__________________________________________________________________________
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值