VB执行SQL语句出错! 5
代码如下PrivateSubbtn_insert_Click()OnErrorGoToErr_btn_insert_ClickDimcnAsADODB.Connectio...
代码如下
Private Sub btn_insert_Click()
On Error GoTo Err_btn_insert_Click
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim mySQL As String
mySQL = "insert into customer_table(Name_Sei, Name_Mei, Kana_Sei, Kana_Mei, Customer_Kbn, " & _
"Company_Name, TelNo, FaxNo, MobileNo, MailAddress, Mobile_Mail, Kanri_Kbn, " & _
"PostCode1, PostCode2, Address1, Address2, Department1, Department2, Position, URL, Business_Type) " & _
"values('1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1')"
Debug.Print mySQL & vbCrLf
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\EigyoSys\mailSys.mdb"
cn.Open
Set cmd = New ADODB.Command
cmd.ActiveConnection = cn
cmd.CommandText = mySQL
cmd.Execute
Exit_btn_insert_Click:
Set cmd = Nothing
cn.Close: Set cn = Nothing
Exit Sub
Err_btn_insert_Click:
Debug.Print Err.Number & vbCrLf & Err.Description & vbCrLf
MsgBox Err.Number & vbCrLf & Err.Description
Set cmd = Nothing
Set cn = Nothing
End Sub
我试过把mySQL改得短一些,就可以正常执行了。
是不是我的做法有问题呢?
谢谢 展开
Private Sub btn_insert_Click()
On Error GoTo Err_btn_insert_Click
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim mySQL As String
mySQL = "insert into customer_table(Name_Sei, Name_Mei, Kana_Sei, Kana_Mei, Customer_Kbn, " & _
"Company_Name, TelNo, FaxNo, MobileNo, MailAddress, Mobile_Mail, Kanri_Kbn, " & _
"PostCode1, PostCode2, Address1, Address2, Department1, Department2, Position, URL, Business_Type) " & _
"values('1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1')"
Debug.Print mySQL & vbCrLf
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\EigyoSys\mailSys.mdb"
cn.Open
Set cmd = New ADODB.Command
cmd.ActiveConnection = cn
cmd.CommandText = mySQL
cmd.Execute
Exit_btn_insert_Click:
Set cmd = Nothing
cn.Close: Set cn = Nothing
Exit Sub
Err_btn_insert_Click:
Debug.Print Err.Number & vbCrLf & Err.Description & vbCrLf
MsgBox Err.Number & vbCrLf & Err.Description
Set cmd = Nothing
Set cn = Nothing
End Sub
我试过把mySQL改得短一些,就可以正常执行了。
是不是我的做法有问题呢?
谢谢 展开
4个回答
展开全部
这样写customer_table表中定义的都是字符类型的才可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
估计有字段类型不是字符型的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
连接符不对造成的吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询