如何更新SQL数据源?
' 说明:SQL数据库:chen 表:xsh 建立了一个DataGridView1,Button1.Click填充,之后修改了一行的数据, Button2.Click 更新数据源Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim jubing As SqlConnection = New SqlConnection("Server=192.168.1.19;DataBase=chen;User ID=sa;Password=sa")
Dim qiaoliang As New SqlDataAdapter()
Dim dataset As New DataSet()
Dim hang As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
qiaoliang.SelectCommand = New SqlCommand()
qiaoliang.SelectCommand.Connection = jubing
qiaoliang.SelectCommand.CommandText = "select * from ren"
qiaoliang.SelectCommand.CommandType = CommandType.Text
dataset.Clear()
jubing.Open()
qiaoliang.Fill(dataset, "lsh")
jubing.Close()
DataGridView1.AutoGenerateColumns = True
DataGridView1.DataSource = dataset
DataGridView1.DataMember = "lsh"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
jubing.Open()
'qiaoliang.Update(dataset.Tables(0)) '当传递具有已修改行的 DataRow 集合时,更新要求有效的 UpdateCommand
'qiaoliang.Update(jubing.ren) '编辑时出现下划线,说明本身就错误
'qiaoliang.Update(dataset) 'Update 无法找到 TableMapping['Table'] 或 DataTable“Table”
'qiaoliang.Update(dataset, "ren") 'Update 无法找到 TableMapping['ren'] 或 DataTable“ren”
'qiaoliang.Update(dataset, "lsh") '当传递具有已修改行的 DataRow 集合时,更新要求有效的 UpdateCommand
'qiaoliang.Update(dataset, lsh) '编辑时出现下划线,说明本身就错误 jubing.Close()
End Sub
End Class
补充:.NET技术 , VB.NET