老师麻烦看看这个代码,有重复的还是会新增加呢?
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "SELECT * F rom {常用账户表}"
dt = cmd.ExecuteReader(True)
Dim s As String = e.Form.Controls("TextBox9").text
s = s.Replace(" ", "")
Dim dv As DataRow '否则在常用账户表查找同名的产品行,将找到的行赋值给变量dv
dv = dt.Find("[账号] = 's '")
If dv Is Nothing Then '如果找到了同名的产品行,也就是dv不是Nothing
MessageBox.Show("该账户信息已经存在,请勿重复添加!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
e.Cancel=True
Return
Else
Dim dr As DataRow = dt.AddNew()
dr("户名") = e.Form.Controls("TextBox10").text
dr("账号") = s
dr("开户银行") = e.Form.Controls("TextBox11").text
dr.Save()
MessageBox.Show("添加成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If
[此贴子已经被作者于2018/9/27 15:54:04编辑过]