有高手说先选择再插入,我用的是ADO,现在已经能插入了,代码如下:Dim Con As ADODB.Connection
Dim rr As ADODB.Recordset
Set Con = New ADODB.Connection
strCon = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=result;Data Source=HZQJCZ;User Id=sa;Password=sa;"
Con.Open strCon
Set rr = New ADODB.Recordset
'添加记录
strsql = "select * from tiaoxiushoufei"
rr.Open strsql, Con, adOpenKeyset, adLockOptimistic
rr.AddNew
rr!车牌号码 = Text20.Text
rr!检测编号 = Text1.Text
rr!调修费用 = Textfy.Text
rr!日期 = Text34.Text
rr.Update
rr.Close
Set rr = Nothing
MsgBox "费用收取成功", vbOKOnly, "提示"怎么加语句,可以防止重复插入啊,不然最后结算统计时钱就多了,我需要用检测编号来判断是否重复,请高手呆板能够帮忙
Dim rr As ADODB.Recordset
Set Con = New ADODB.Connection
strCon = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=result;Data Source=HZQJCZ;User Id=sa;Password=sa;"
Con.Open strCon
Set rr = New ADODB.Recordset
'添加记录
strsql = "select * from tiaoxiushoufei"
rr.Open strsql, Con, adOpenKeyset, adLockOptimistic
rr.AddNew
rr!车牌号码 = Text20.Text
rr!检测编号 = Text1.Text
rr!调修费用 = Textfy.Text
rr!日期 = Text34.Text
rr.Update
rr.Close
Set rr = Nothing
MsgBox "费用收取成功", vbOKOnly, "提示"怎么加语句,可以防止重复插入啊,不然最后结算统计时钱就多了,我需要用检测编号来判断是否重复,请高手呆板能够帮忙
2,con.execute "if (select count(*) from tiaoxiushoufei where 检测编号='"& text1.text &"')=0 insert into tiaoxiushoufei(车牌号码,检测编号,调修费用,日期) values('"& text20.text &"','"& text1.text &"',"& textfy.text &",'"& text34.text &"')"
Dim Con As ADODB.Connection
Dim rr As ADODB.Recordset
Set Con = New ADODB.Connection
Dim strsql As String
strCon = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=result;Data Source=HZQJCZ;User Id=sa;Password=sa;"
Con.Open strCon
strsql = " If Exists (Select * From tiaoxiushoufei Where 车牌号码 = '" & Text20.Text & "') " _
& " Update tiaoxiushoufei " _
& " Set 检测编号 = '" & Text1.Text & "', " _
& " 调修费用 = '" & Textfy.Text & "' , " _
& " 日期 = '" & Text34.Text & "' " _
& " where 车牌号码 = '" & Text20.Text & "';" _
& " Else " _
& " Insert Into tiaoxiushoufei (车牌号码,检测编号,调修费用,日期) " _
& " Values ( " _
& "'" & Text20.Text & "', " _
& "'" & Text1.Text & "', " _
& "'" & Textfy.Text & "', " _
& "'" & Text20.Text & "') ;"
Con.Execute strsql
MsgBox 费用收取成功", vbOKOnly, "提示"
Dim rs As ADODB.Recordset
Set Con = New ADODB.Connectionrs.open"select 检测编号 from tiaoxiushoufei where 检测编号='"&trim(text1)&"'",Con, adOpenKeyset, adLockOptimistic
if rs.recordcount>0 then
'不执行插入
MsgBox "编号已经存在", vbOKOnly, "提示"
else
'否则插入
con.execute("insert into tiaoxiushoufei values('"& text20.text &"','"& text1.text &"',"& textfy.text &",'"& text34.text &"')")
endif
Dim Con As ADODB.Connection
Dim Rs As ADODB.Recordset
Set Con = New ADODB.Connection
Rs.Open "Select * from tiaoxiushoufei where 检测编号='"& text1.text &"'",Con,1,1
If Rs.Eof then
Rs.Close
这里写插入代码 可用 con.Execute "insert into tablename(字段1,字段2,字段3) values(值1,值2,值3)"End if
Dim Rs As New ADODB.Recordset
这行有问题吗??
Dim Rs As New ADODB.Recordset
Con.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=result;Data Source=HZQJCZ;User Id=sa;Password=sa;"
Rs.open "select 检测编号 from tiaoxiushoufei where 检测编号='"&trim(text1)&"'",Con,adOpenKeyset,adLockOptimistic
if Rs.Recordcount<1 then
Con.Execute "insert into tablename(车牌号码,检测编号,调修费用,日期) values('"& text20.text &"','"& text1.text &"',"& textfy.text &",'"& text34.text &"')"
end if
Rs.Close
Set Rs = Nothing
Con.close
Set Con=Nothing