主题:关于VB.net数据库连接的问题?
sunboyzb
[专家分:60] 发布于 2005-12-01 23:57:00
我现在想连接ACCESS数据库,怎样连接才是最好的呀?如果要写成类我该怎么写才是最好的?(还有一个小小的问题,在VB6里有app.path,但.net中该用什么才能使应用程序动态适应环境呢?)
回复列表 (共3个回复)
沙发
lqqkk [专家分:40] 发布于 2005-12-03 23:53:00
你可以参考一下以下的连接方法:
'定义程序启动的路径
Dim absPath As String = Application.StartupPath
'定义数据库连接
Protected strcnn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & absPath & "\data.mdb"
Dim cnn As New System.Data.OleDb.OleDbConnection(strcnn)
板凳
shengxinghui [专家分:40] 发布于 2005-12-25 00:30:00
System.IO.Directory.GetCurrentDirectory
3 楼
andy5337 [专家分:760] 发布于 2005-12-26 10:47:00
Imports System.Data
Imports System.Data.OleDb
Dim connStr, selectCmd As String
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= “表存在的路径”"
selectCmd = "select * from 表"
Dim conn As OleDbConnection, cmd As OleDbCommand
conn = New OleDbConnection(connStr)
conn.Open()
cmd = New OleDbCommand(selectCmd, conn)
cmd.ExecuteNonQuery()
conn.Close()
我来回复