下面是删除,为什么实现不了?
Dim str As String
 Dim con As New ADODB.Connection
Dim re As New ADODB.Recordset
Dim strq As Strings = InputBox("请输入要删除的学生姓名:", "删除信息", 0)con.Open "dsn=studentDS1"
 str = "delete  from student where  姓名= ' " & s & " '"
     con.Execute (str)
con.Close
下面是添加
Dim con As ADODB.Connection
Dim re As ADODB.Recordset
Dim strq As String
Dim s As Long
  s = MsgBox("你要添加此条信息吗?", vbYesNo, "添加信息")
  If s = vbYesNo Then
  
con.Open "dsn=studentDS1"
strq = "insert into student values('" & Form5.Text1.Text & " ','" & Form5.Text2.Text & _
        " ','" & Form5.Text3.Text & " ','" & Form5.Text4.Text & " ','" & Form5.Text5.Text & _
        " ','" & Form5.Text6.Text & " ','" & Form5.Text7.Text & " ','" & Form5.Text8.Text & " ')"
   con.Execute strq
 con.Close
End If

解决方案 »

  1.   

    检查一下连接是否有问题
    另外,连接定义成public比较好,否则每次操作都要打开、关闭,太麻烦
      

  2.   

    下面是删除学生的所有信息,为什么实现不了?
    Dim str As String
     Dim con As New ADODB.Connection
    Dim re As New ADODB.Recordset
    Dim strq As Strings = InputBox("请输入要删除的学生姓名:", "删除信息", 0)’输入学生的姓名con.Open "dsn=studentDS1"
     str = "delete  from student where  姓名= ' " & s & " '"  ‘删除的SQL语句
         con.Execute (str)‘执行语句
    con.Close
    下面是添加学生的信息,怎么实现?
    Dim con As ADODB.Connection
    Dim re As ADODB.Recordset
    Dim strq As String
    Dim s As Long
      s = MsgBox("你要添加此条信息吗?", vbYesNo, "添加信息")
      If s = vbYesNo Then
      
    con.Open "dsn=studentDS1"
    strq = "insert into student values('" & Form5.Text1.Text & " ','" & Form5.Text2.Text & _
            " ','" & Form5.Text3.Text & " ','" & Form5.Text4.Text & " ','" & Form5.Text5.Text & _
            " ','" & Form5.Text6.Text & " ','" & Form5.Text7.Text & " ','" & Form5.Text8.Text & " ')"  ‘SQL语句
       con.Execute strq   ’执行语句
     con.Close
    End If
    如果这样不能实现应该怎么写?
    谢谢!!!!!!!!
      

  3.   

    在con.exectute strq后写
    strq="select * from student"
    rs.open strq,con
    再试试。
      

  4.   

    SQL语句的问题
    把生成的语句复制到数据库中执行一下
    看看是什么结果.
      

  5.   

    str = "delete  from student where  姓名= '" & s & "'"  '删除的SQL语句,你的S前后都加了一个空格,所以不行,删除那两个空格。
      

  6.   

    不然你在执行前用msgbox str,看一看这个str正确与否。
      

  7.   

    少了rs.open 只打开了数据库,未打开记录集
      

  8.   

    str = "delete  from student where  姓名= '" & trim(s) & "'"下面是添加学生的信息,怎么实现?
    Dim con As ADODB.Connection
    Dim re As ADODB.Recordset
    Dim strq As String
    Dim s As Long
      s = MsgBox("你要添加此条信息吗?", vbYesNo, "添加信息")
    If s = vbYes Then
      
    con.Open "dsn=studentDS1"
    strq = "insert into student values('" & Form5.Text1.Text & " ','" & Form5.Text2.Text & _
            " ','" & Form5.Text3.Text & " ','" & Form5.Text4.Text & " ','" & Form5.Text5.Text & _
            " ','" & Form5.Text6.Text & " ','" & Form5.Text7.Text & " ','" & Form5.Text8.Text & " ')"  ‘SQL语句
       con.Execute strq   ’执行语句
     con.Close
    End If
    看看好用不好用啊!
      

  9.   

    str = "delete student where  姓名= '" & trim(s) & "'"不好意思啊!删除语句中不用使用FROM
      

  10.   

    是rs.open sql,cnn,*,*  这两个参数不对的原因,你设置成readonly的话就不能添加删除。
      

  11.   

    1。在str = "delete  from student where  姓名= ' " & s & " '"语句后敲
    debug.print s
    看看拼成后的SQL语句是否正确?
    2。con.Execute (str)这句改为
    dim ret as integer
    ret = con.Execute (str)
    debug.print "ret=" & ret
    看看ret的返回值是多少,如果不为0肯定是出错了。
      

  12.   

    我觉得应该是
    dim cmd as addodb.command
    cmd.commandtext="delete from student where 姓名= '"&trim(s)&"'
    cmd.execute
    这条语句应该可以的,我现在也在做这方面的。这条语句我用过的,而且我是删除远程机器上的数据。
    你试试看