Dim Ds As New DataSet()
Dim Tb As New DataTable()
Dim Ad As New Microsoft.Data.Odbc.OdbcDataAdapter()
这是这是修改“保存”的代码
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If ZTMC.Text = "" Or SBDWMC.Text = "" Or DWIP.Text = "" Then
MsgBox("对不起,请您将数据输入完整!", MsgBoxStyle.YesNo, "提示")
Else
Dim row1 As Integer
Try
row1 = DataGrid1.CurrentCell.RowNumber
'Tb.Rows(row1)("ZTBH") = ZTBH.Text
Tb.Rows(row1)("ZTMC") = ZTMC.Text
Tb.Rows(row1)("SBDWDM") = sbdwdm.Text
Tb.Rows(row1)("SBDWMC") = SBDWMC.Text
Tb.Rows(row1)("DWIP") = DWIP.Text
Tb.Rows(row1)("SM") = SM.Text
Tb.Rows(row1)("DATABASET") = databasetype.Text
Ad.Update(Ds, "ZTXX")
Button3.Enabled = False
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "提示")
End Try
End If
End Sub
这是你选择某条记录之后把数据读到文本框中的代码
Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
Dim row As Integer
If Tb.Rows.Count < 1 Then
Exit Sub
End If
Try
row = DataGrid1.CurrentCell.RowNumber
ZTBH.Text = Tb.Rows(row)("ZTBH")
ZTMC.Text = Tb.Rows(row)("ZTMC")
sbdwdm.Text = Tb.Rows(row)("SBDWDM")
SBDWMC.Text = Tb.Rows(row)("SBDWMC")
DWIP.Text = Tb.Rows(row)("DWIP")
SM.Text = Tb.Rows(row)("SM")
databasetype.Text = Tb.Rows(row)("DATABASET")
ZTBH.ReadOnly = True
'Button1.Enabled = False
'Button2.Enabled = True
Button3.Enabled = True
'Button4.Enabled = True
Button5.Enabled = True
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "提示")
End Try
END SUB
这个是“删除”的代码
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim row, i As Integer
row = DataGrid1.CurrentCell.RowNumber
If Ds.Tables("ZTXX").Rows.Count <> 0 Then
If MsgBox("是否确定要删除选择的行?", MsgBoxStyle.YesNo, "提示") = MsgBoxResult.Yes Then
Ds.Tables("ZTXX").Rows(row).Delete()
Ad.Update(Ds, "ZTXX")
End If
End If
End Sub