VB中怎么连接ACCESS数据库,并且读取表中数据?
我的数据库放在F:\vb数据\DataBase\DataBase2007.mdb程序在:F:\vb数据\请问怎么连接数据库(可移植的),并且把表admin_user中的数...
我的数据库放在F:\vb数据\DataBase\DataBase2007.mdb
程序在:F:\vb数据\
请问怎么连接数据库(可移植的),并且把表admin_user中的数据用DataGrid
读出来?哪位大虾帮帮忙? 展开
程序在:F:\vb数据\
请问怎么连接数据库(可移植的),并且把表admin_user中的数据用DataGrid
读出来?哪位大虾帮帮忙? 展开
展开全部
Set cn = New ADODB.Connection
sqldata="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.mappath("F:\vb数据\DataBase\DataBase2007.mdb ")
cn.Open sqldata
Set adors = New ADODB.Recordset
adors.Open strsql, cn
MSFlexGrid1.Rows = 1
While Not adors.EOF
MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
MSFlexGrid1.Row = MSFlexGrid1.Rows - 1
MSFlexGrid1.Col = 0
MSFlexGrid1.Text = adors.Fields(0)
MSFlexGrid1.Col = 1
MSFlexGrid1.Text = adors.Fields(1)
MSFlexGrid1.Col = 2
MSFlexGrid1.Text = adors.Fields(2)
adors.MoveNext
Wend
sqldata="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.mappath("F:\vb数据\DataBase\DataBase2007.mdb ")
cn.Open sqldata
Set adors = New ADODB.Recordset
adors.Open strsql, cn
MSFlexGrid1.Rows = 1
While Not adors.EOF
MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
MSFlexGrid1.Row = MSFlexGrid1.Rows - 1
MSFlexGrid1.Col = 0
MSFlexGrid1.Text = adors.Fields(0)
MSFlexGrid1.Col = 1
MSFlexGrid1.Text = adors.Fields(1)
MSFlexGrid1.Col = 2
MSFlexGrid1.Text = adors.Fields(2)
adors.MoveNext
Wend
展开全部
选添加ADODB控件
Function o_Connection() As ADODB.Connection
Dim Conn
Dim AuthConnectionString As String
Set Conn = CreateObject("ADODB.Connection")
AuthConnectionString = "DBQ=" & App.Path & "\don.mdb;Driver={Microsoft Access Driver (*.mdb)};"
Conn.Open AuthConnectionString
Set o_Connection = Conn
End Function
Function rs_hs(sql As String, Conn As ADODB.Connection) As ADODB.Recordset
If InStr(UCase(sql), "INSERT") > 0 Or InStr(UCase(sql), "DROP") > 0 Or InStr(UCase(sql), "DELETE") > 0 Or InStr(UCase(sql), "CREATE") Then
Conn.Execute sql
Else
Dim rs1 As New ADODB.Recordset
rs1.Open sql, Conn, 3, 3
End If
Set rs_hs1 = rs1
End Function
这是我写的一套数据库打开函数可直接用
至于SQL只要将
"DBQ=don.mdb;Driver={Microsoft Access Driver (*.mdb)};"
改为"Provider=Sqloledb; User ID=sa; Password=; Initial Catalog = abcd; Data Source=(local)"
就OK了
Function o_Connection() As ADODB.Connection
Dim Conn
Dim AuthConnectionString As String
Set Conn = CreateObject("ADODB.Connection")
AuthConnectionString = "DBQ=" & App.Path & "\don.mdb;Driver={Microsoft Access Driver (*.mdb)};"
Conn.Open AuthConnectionString
Set o_Connection = Conn
End Function
Function rs_hs(sql As String, Conn As ADODB.Connection) As ADODB.Recordset
If InStr(UCase(sql), "INSERT") > 0 Or InStr(UCase(sql), "DROP") > 0 Or InStr(UCase(sql), "DELETE") > 0 Or InStr(UCase(sql), "CREATE") Then
Conn.Execute sql
Else
Dim rs1 As New ADODB.Recordset
rs1.Open sql, Conn, 3, 3
End If
Set rs_hs1 = rs1
End Function
这是我写的一套数据库打开函数可直接用
至于SQL只要将
"DBQ=don.mdb;Driver={Microsoft Access Driver (*.mdb)};"
改为"Provider=Sqloledb; User ID=sa; Password=; Initial Catalog = abcd; Data Source=(local)"
就OK了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询