如何在程序中,添加对数据库的连接,及如何写入SQL语句!
我用的是ADO,DataGrid,数据库是Access ,要是有SQl Server 的也行啊!
问题解决,马上结贴!谢谢!

解决方案 »

  1.   

    dim ac_tmp as new adodb.connection
    dim ar_tmp as new adodb.recordset
    '连接数据库
    With ac_tmp
        If .State = adStateOpen Then .Close
        .ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\数据库名.mdb;Mode=ReadWrite;Persist Security Info=False"
        .Open
    End With
    '打开某个数据表
    If ar_Tmp.State = adStateOpen Then ar_Tmp.Close
    ar_Tmp.Open "select * from 表名", ac_tmp, adOpenKeyset, adLockReadOnly
    set datagrid.datasource=ar_tmp
      

  2.   

    这种问题最好自己系统的看书。 给你推荐一本
    书名:ADO编程技术          
     
    原书名: Programming ADO [原书信息]  
    原出版社 Microsoft Press  
    作者: David Sceppa  
    译者: 石均 葛俊等  
    书号: 7-900630-89-9 
    页码: 320 
    开本:  
    丛书名 Microsoft 编程系列  
    出版社: 清华大学出版社  
    出版日期:  2001-1-1
      

  3.   

    to  Leftie(左手) 
    出现错误 找不到可用的 ISAM 
    帮帮忙啦!
      

  4.   

    '工程-〉引用 Microsoft Active Data Objects 2.x(x表示版本号)
    Dim cn As New ADODB.Connection
    Dim rs As New Recordset
    cn.ConnectionString = "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=pubs;User Id=sa;Password=lyjlee;"
    cn.Open
    rs.Open "authors", cn, adOpenKeyset, adLockOptimisticif not rs.eof then
    do while not rs.eof
    debug.print rs("au_lname")
    rs.movenext
    loop
    end if
    rs.close
    cn.close