你的 values 前后需要有空格,不然Sql会报错

解决方案 »

  1.   

    "insert into 学生信息表  values ('" & Text1(0).Text & "','" & Text1(1).Text & "','" & Combo1.Text + "','" & Text1(3).Text & "','" + Text1(4).Text & "','" & Text1(5).Text & "','" & Text1(6).Text & "','" & Text1(7).Text + "')"学生信息表里的列名取消掉,把表中每一列都一一对应好,没有内容的就用空
      

  2.   

    单步调试,将SQL语句赋值给一个变量,单步到这个赋值后,将其显示在立即窗口中,拷贝上来看看。
      

  3.   

    相似的两段代码,下面这一个可以用,为什么上面问题贴的却不能用?  求解Private Sub Command1_Click()
    On Error Resume Next
    Dim cnn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim mrc As New ADODB.Recordset
    If Text1(0).Text = "" Or Text1(1).Text = "" Or Text1(2).Text = "" Or DataCombo1.BoundText = "" Then
        MsgBox "信息不完整,无法保存!"
    Else
        cnn.ConnectionString = "FILE NAME=C:\Program Files\Common Files\ODBC\Data Sources\student_link.dsn"
        cnn.Open
        Set rs = cnn.Execute("insert into stud_grade(stud_id,name,course_id,grade)values('" + Text1(0).Text + "','" + Text1(1).Text + "','" + DataCombo1.BoundText + "','" + Text1(2).Text + "')")
        txtsql = "select * from stud_grade where stud_id='" + Text1(0).Text + "'and name='" + Text1(1).Text + "'and course_id='" + DataCombo1.BoundText + "'and grade='" + Text1(2).Text + "'"
        Set mrc = cnn.Execute(txtsql)
        
        If mrc.EOF = True Then
           MsgBox "添加失败!", , "信息提示"
        
        Else
           
             Me.Adodc4.Refresh
            Form7.Adodc1.Refresh
        
             MsgBox "添加成功!", , "信息提示"
        
        End If
        cnn.Close
    End If
       
    End Sub