怎么如何用VB软件连接数据库
- 提问者网友:几叶到寒
- 2021-07-29 19:43
- 五星知识达人网友:山河有幸埋战骨
- 2021-07-29 20:22
strAppPath = App.Path
If Right(strAppPath, 1) <> "\" Then
strAppPath = strAppPath & "\"
End If
strAppPath = strAppPath & "BigText.mdb"
ConnectString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & strAppPath & ""
Set cnn = New ADODB.Connection
cnn.Open ConnectString
'-----------------sql
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim str As String
cnn.CursorLocation = adUseClient
str = "Provider=SQLOLEDB.1;Persist Security Info =False;" _
& "User ID=sa;" _ '数据库的登录名
& "Pwd=123456;" _ '数据库的密码
& "Initial Catalog=db1;" _
& "Data Source=whx" '连接数据库的名字
cnn.Open str
- 1楼网友:煞尾
- 2021-07-29 23:38
经典VB连接数据库语句。
<% set conn=server.CreateObject("adodb.connection") str="Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.MapPath("---/---.mdb") conn.open str %>
- 2楼网友:愁杀梦里人
- 2021-07-29 22:46
dim dbConn As ADODB.Connection '定义一个ADODB连接 dim MenuRs As ADODB.Recordset '定义Recordset对象 dim WordRs As ADODB.Recordset
Function Conn2DB(byval dbname as string) As Boolean '数据库连函数,dbname为数据库文件的绝对路径
Dim connStr As String
' Access连接字符串 conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbName & ";Persist Security Info=False;Jet OLEDB:Database Password=abcdef"
Set dbConn = New ADODB.Connection '定义一个ADODB连接对象
If dbConn.State <> adStateOpen Then '判断ADODB连接是否打开 dbConn.Open conStr '如果不是打开状态 就打开连接 End If
Conn2DB = True End Function
Function CloseDb() As Boolean If dbConn.State = adStateOpen Then dbConn.Close: Set dbConn = Nothing End If End FunctionPrivate Sub Form_Load()
dim dbname as string
dbname="D:\db.mdb" ‘数据库文件路径
if Conn2DB(dbname)=true then
msgbox "连接数据库成功!"
CloseDb
end if End sub
- 3楼网友:过活
- 2021-07-29 21:58