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

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语句
__________________________________________________________________________
看了很多,都晕了,学习中。
__________________________________________________________________________
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VB.NET使用MySQL数据库连接并显示数据DataGrid的步骤如下: 1. 首先,确保已经安装并导入了MySQL连接器。在项目添加对`MySql.Data.dll`的引用。 2. 创建MySQL连接:使用`MySqlConnection`类来连接MySQL数据库。需要传递连接字符串,包括服务器地址、用户名、密码等信息。 ```vb Dim conn As MySqlConnection = New MySqlConnection("server=localhost;user id=root;password=1234;database=mydatabase") ``` 3. 打开连接:使用`Open()`方法打开连接。 ```vb conn.Open() ``` 4. 创建SQL查询字符串:可以根据需要编SELECT语句,并将其分配给一个字符串变量。 ```vb Dim sql As String = "SELECT * FROM mytable" ``` 5. 创建DataAdapter和DataSet:使用`MySqlDataAdapter`类和`DataSet`类来填充数据。 ```vb Dim da As MySqlDataAdapter = New MySqlDataAdapter(sql, conn) Dim ds As DataSet = New DataSet() ``` 6. 填充DataSet:使用`Fill()`方法将数据填充到DataSet。 ```vb da.Fill(ds, "mytable") ``` 7. 绑定DataGrid:使用`SetDataBinding()`方法将DataSet绑定到DataGrid。 ```vb DataGrid1.SetDataBinding(ds, "mytable") ``` 8. 关闭连接:使用`Close()`方法关闭数据库连接。 ```vb conn.Close() ``` 通过以上步骤,您可以成功地将MySQL数据显示在VB.NETDataGrid。请注意,在连接MySQL数据库之前,您需要确保已经正确安装并配置了MySQL数据库,并且需要正确提供数据库连接字符串的服务器地址、用户名、密码等信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值