请教一个VB中使用SQL语句的问题!
请教各位大侠:
在一个commandbotton cleck事件中写入此语句!
Set adors = adocon.Execute( "insert into zgk values( " & Text1 & ", ' " & Text2 & " ', ' " & Text3 & " ', ' " & Text4 & " ', ' " & Text5 & " ', ' " & Text6 & " ', ' " & Text7 & " ') ")
运行时老是返回“要求对象错误”,该表单中确实有TEXT1~TEXT7控件啊!请问是什么问题呢?另外,分隔符 '和符号 "各自的作用是什么呢?
[解决办法]
正解如下:
Call main
Dim RSRowCount As Long
RSRowCount = CLng(adocon.Execute( "select * from zgk where zgh= ' " + Text1.Text + " ' ")(0))
If RSRowCount = 0 Then
c = MsgBox( "确认要保存该信息吗? ", 32, "职工信息管理 ")
If c = vbOK Then
On Error Resume Next
adocon.Execute "insert into zgk values( " & Text1 & ", ' " & Text2 & " ', ' " & Text3 & " ', ' " & Text4 & " ', ' " & Text5 & " ', ' " & Text6 & " ', ' " & Text7 & " ') "
If Err.Number = 0 Then
MsgBox "数据保存成功!! ", 64, "职工信息管理 "
Else
MsgBox "数据保存失败,原因是: " & Err.Description, 16, "错误信息 "
Err.Clear
End If
cmd_save.Enabled = False
cmd_add.Enabled = True
Else
End If
Else
MsgBox "对不起,该信息已经保存过,不能再进行保存 ", 64, "职工信息管理 "
End If
Adodc1.RecordSource = "select * from zgk order by zgh "
Adodc1.Refresh
adocon.Close
[解决办法]
就看SQL SERVER自带文档,内容齐全,省钱省力!
我个人建议你要提升如下功力:
1.命名规则;
2.中央除错;
3.ADO编程;