欢迎你访问我的个人网站:www.6ideas.cn,资料更丰富.

asp下面的數據庫操作(VB)

Posted on 2007-04-11 19:45  talantlee  阅读(502)  评论(0)    收藏  举报
  1>asp下面一個普通的access/sql連接
<%
   Set CountConn = Server.CreateObject("ADODB.Connection")
   CountFile = Server.MapPath("pic.mdb")
   CountConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("pic.mdb")
'Const strConnectString = "Provider=sqloledb;User ID=pubsLogin; pwd=pubsPassword; Data Source=YourServerName; Initial Catalog=pubs"
   Set rs = Server.CreateObject("ADODB.RecordSET")
   rs.Open "Select * from count where id = '" & id & "'",CountConn,1,1
   If not rs.EOF Then
    count = rs("count")
    End If
    rs.Close

%>

2>asp下面一個普通的mysql連接
寫法和上面的一樣,但連接字串不同
'connect to MySQL server using MySQL ODBC 3.51 Driver(使用MySQL ODBC 3.51驱动程序连接到MySQL服务器)
conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};"_
                      & "SERVER=localhost;"_
                      & " DATABASE=test;"_
                      & "UID=venu;PWD=venu; OPTION=3"
3>Example
   Dim cn As ADODB.Connection
    
Dim cmd As ADODB.Command
    
Dim rs As ADODB.Recordset
    
    
Set cn = New ADODB.Connection
    
Set cmd = New ADODB.Command
    
Set rs = New ADODB.Recordset
        
    
' Open the Connection object to either the IOM or SAS/SHARE provider.
    
    cmd.ActiveConnection 
= cn
    
    
' Create a new table.
    cmd.CommandText = "create table sasuser.newtable ( i num, name char(40), age num );"
    cmd.Execute
    
    
' Insert values into the new table.
    cmd.CommandText = "insert into sasuser.newtable values( 0, ""Bill"", 32 ) values( 1, ""John"", 99 );"
    cmd.Execute
    
     
' Open a Recordset object on the new table.
    cmd.CommandText = "select * from sasuser.newtable"
    
Set rs = cmd.Execute()
    
    
' Do something with the recordset.
    MsgBox rs.GetString
    
    rs.Close
    cn.Close

Sub Main()
    
Dim cn As ADODB.Connection
    
Dim rs As ADODB.Recordset

    
Set cn = New ADODB.Connection
    
Set rs = New ADODB.Recordset
          
    
' Open the Connection Object to either the IOM or SAS/SHARE provider.
    
    
' Create a new table.
    cn.Execute "create table sasuser.newtable ( i num, name char(40), age num );"
    
' Insert values into the new table.
    cn.Execute "insert into sasuser.newtable values( 0, ""Bill"", 32 ) values( 1, ""John"", 99 );"
    
' Open a Recordset object on the new table.
    Set rs = cn.Execute("select * from sasuser.newtable")
    
' Do something with the Recordset.
    MsgBox rs.GetString
    
    rs.Close
    cn.Close

End Sub


博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3