首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

各位前辈,紧急紧急求救,为什么总出现INSERT INTO 语法异常

2012-02-29 
各位前辈,紧急紧急求救,为什么总出现INSERT INTO 语法错误?PrivateSubCommand1_Click()DimsqlAsStringDimr

各位前辈,紧急紧急求救,为什么总出现INSERT INTO 语法错误?
Private   Sub   Command1_Click()
Dim   sql   As   String
Dim   rst   As   ADODB.Recordset
Dim   con   As   New   ADODB.Connection
Dim   j   As   Integer
Dim   nowdate   As   String

                Set   con   =   New   ADODB.Connection
              con.ConnectionString   =   "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source=swdata.mdb;Persist   Security   Info=False "
              con.CursorLocation   =   adUseClient
              con.Open
              Set   rst   =   con.Execute( "select   *   from   CustInfo ")
              j   =   rst.RecordCount
                If   Text2.Text   =   " "   Or   Text17.Text   =   " "   Or   Text20.Text   =   " "   Or   Text4.Text   =   " "   Then
                msg   =   MsgBox( "请填充必填字段! ",   vbOKCancel,   "警告 ")
                       
                Else
          j   =   j   +   1
             
          con.Execute   ( "insert   into   CustInfo   (user,RecdDate,Com,legalRep,Kwd,MktBrd,Credit,source,importance,businature,state,Bank,Account,TaxNo,Country,Province,City,Add,Zip,Profile,Contact,Gender,   Title,Mobile,Tel,Fax,Email,Web) "   _
&   "   select   ' "   &   CStr(j)   &   " ', ' "   &   Trim(Text24.Text)   &   " ', ' "   &   DTPicker1.Value   &   " ', ' "   &   Trim(Text2.Text)   &   " ', ' "   &   Trim(Text3.Text)   &   " ', ' "   &   Trim(Text4.Text)   &   " ', ' "   &   Trim(Text5.Text)   &   " ', ' "   &   Trim(Text7.Text)   &   " ', ' "   &   Trim(Combo2.Text)   &   " ', ' "   &   Trim(Combo3.Text)   &   " ', ' "   &   Trim(Combo4.Text)   &   " ', ' "   &   Trim(Combo5.Text)   &   " ', ' "   &   Trim(Combo6.Text)   &   " ', ' "   &   Trim(Text8.Text)   &   " ', ' "   &   Trim(Text9.Text)   &   " ', ' "   &   Trim(Text10.Text)   &   " ', ' "   &   Trim(Text11.Text)   &   " ', ' "   &   Trim(Text12.Text)   &   " ', ' "   &   Trim(Text13.Text)   &   " ', ' "   &   Trim(Text14.Text)   &   " ', ' "   &   Trim(Text15.Text)   &   " ', ' "   &   Trim(Text16.Text)   &   " ', ' "   &   Trim(Text17.Text)   &   " ', ' "   &   Trim(Combo1.Text)   &   " ', ' "   &   Trim(Text18.Text)   &   " ', ' "   &   Trim(Text19.Text)   &   " ', ' "   &   Trim(Text20.Text)   &   " ', ' "   &   Trim(Text21.Text)   &   " ', ' "   &   Trim(Text22.Text)   &   " ', ' "   &   Trim(Text23.Text)   &   " ' ")


     
     
                      MsgBox   "数据添加成功! ",   vbOKOnly,   "恭喜! "
                End   If
End   if

[解决办法]
把con.Execute 后面SQL用一个变量来表达,然后在con.Execute 处中断一下,把该变量打印出来,分析一下哪儿出错了。
[解决办法]
将select改为values
[解决办法]
jjkk168(老加班的人--好好学习,天天吃饭)
将select改为values

---------------------------------------
sql拼错了



[解决办法]
1,格式:con.execute "insert into tablename(...) values(...) "
2,user是关键字,改成[user]
[解决办法]
我一般处理SQL语句的方法很少这样连接,这样连接字符串极容易出错,并且还不好查

我处理的方法如下,建议这样修改

Dim strSQL As String
strSQL = "Insert Into CustInfo ([user],[RecdDate],[Com],[legalRep],[Kwd]) Values( '%USER% ', '%RECDDATE% ', '%COM% ', '%LEGALREP% ', '%KWD% ')
strSQL = Replace(strSQL, '%USER% ',Trim(Text1.Text))
strSQL = Replace(strSQL, '%RECDDATE% ',Trim(Text2.Text))
.......................

热点排行