vb6.0中向access表中添加数据时判断是否有相同的
PrivateSubCommand1_Click()OnErrorResumeNextAdodc1.Recordset.MoveFirstForI=1ToAdodc1.R...
Private Sub Command1_Click()
On Error Resume Next
Adodc1.Recordset.MoveFirst
For I = 1 To Adodc1.Recordset.RecordCount
If Adodc1.Recordset.Fields("场编号") = Text3.Text And Adodc1.Recordset.Fields("仪器编号") = Text4.Text Then
MsgBox "此仪器已存在,请重新输入", , "提示"
Adodc1.Recordset.MoveFirst
Exit Sub
End If
Adodc1.Recordset.MoveNext
Next I
With Adodc1
.Recordset.AddNew
.Recordset.Fields(1).Value = Text1.Text '仪器名称
.Recordset.Fields(2).Value = Text2.Text '型号
.Recordset.Fields(3).Value = Text3.Text '场编号
.Recordset.Fields(4).Value = Text4.Text '仪器编号
.Recordset.Fields(5).Value = Text5.Text '生产厂家
.Recordset.Fields(6).Value = Text6.Text '有效期至
.Recordset.Fields(7).Value = Text7.Text '量程
.Recordset.Fields(8).Value = Text8.Text '准确度
.Recordset.Update
End With
Text1.Text = "" '工程名称
Text2.Text = "" '项目名称
Text3.Text = "" '合同工号
Text4.Text = "" '委托单位
Text5.Text = "" '项目金额
Text6.Text = "" '合同有效期
Text7.Text = "" '带资比例
Text8.Text = "" '带资比例
Set Form1.MSHFlexGrid1.DataSource = Adodc1
Form1.MSHFlexGrid1.Refresh
End Sub
为什么点添加后一直提存在相同的呢,数据库应当这么写的吧 展开
On Error Resume Next
Adodc1.Recordset.MoveFirst
For I = 1 To Adodc1.Recordset.RecordCount
If Adodc1.Recordset.Fields("场编号") = Text3.Text And Adodc1.Recordset.Fields("仪器编号") = Text4.Text Then
MsgBox "此仪器已存在,请重新输入", , "提示"
Adodc1.Recordset.MoveFirst
Exit Sub
End If
Adodc1.Recordset.MoveNext
Next I
With Adodc1
.Recordset.AddNew
.Recordset.Fields(1).Value = Text1.Text '仪器名称
.Recordset.Fields(2).Value = Text2.Text '型号
.Recordset.Fields(3).Value = Text3.Text '场编号
.Recordset.Fields(4).Value = Text4.Text '仪器编号
.Recordset.Fields(5).Value = Text5.Text '生产厂家
.Recordset.Fields(6).Value = Text6.Text '有效期至
.Recordset.Fields(7).Value = Text7.Text '量程
.Recordset.Fields(8).Value = Text8.Text '准确度
.Recordset.Update
End With
Text1.Text = "" '工程名称
Text2.Text = "" '项目名称
Text3.Text = "" '合同工号
Text4.Text = "" '委托单位
Text5.Text = "" '项目金额
Text6.Text = "" '合同有效期
Text7.Text = "" '带资比例
Text8.Text = "" '带资比例
Set Form1.MSHFlexGrid1.DataSource = Adodc1
Form1.MSHFlexGrid1.Refresh
End Sub
为什么点添加后一直提存在相同的呢,数据库应当这么写的吧 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询