16,554
社区成员
发帖
与我相关
我的任务
分享
Public Class chengbenhesuan
Public SqlServerCon As New SqlClient.SqlConnection
Private CoedSet As New DataSet
Private Bind_Coed As New Windows.Forms.BindingSource
Private adp_Coed As SqlClient.SqlDataAdapter
Private Sub 绑定数据_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim query As String
query = "SELECT * FROM zcb"
adp_Coed = New SqlClient.SqlDataAdapter(query, cn) '执行SQL查询语句.获取相关款号的数据
CoedSet.Clear() '清空临时数据表
adp_Coed.Fill(CoedSet, "code")
Bind_Coed.DataSource = CoedSet.Tables("code")
DataGridView2.DataSource = Bind_Coed '绑定数据表
End Sub
Private Sub 保存_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
DataGridView2.EndEdit() '结束编辑动作
Bind_Coed.EndEdit() '结束编辑动作
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Dim changedst As New DataSet
changedst = CoedSet
If Not changedst Is Nothing Then
Dim com As New SqlClient.SqlCommandBuilder(adp_Coed)
Try
adp_Coed.Update(CoedSet.Tables("code"))
Catch err1 As SqlClient.SqlException
MsgBox(err1.Message)
End Try
End If