我正在使用以下代码编辑我的连接字符串
Dim adapter As New dbSQLServerTestDataSet1.tblContact
Dim conn As New SqlConnection()
conn.ConnectionString = "Data Source=" & vrCompName & "\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbSQLServerTest.mdf;Integrated Security=True;User Instance=True"
adapter.Connection = conn
Dim table As DataTable = adapter.GetData()
但它在
上出错Dim adapter As New dbSQLServerTestDataSet1.tblContact
在该行的dbSQLServerTestDataSet1.tblContact
部分。这些对象确实在我的项目中退出。我还导入了System.Data
和System.Data.SqlClient
。
请指导。
答案 0 :(得分:0)
添加命名空间
Imports System.Data.SqlClient
然后使用以下代码:
Dim ds As dsTestCon
Me.taTestCon.Fill(Me.DsTestCon.tblTest)
MsgBox(DsTestCon.tblTest.Rows(0).Item(1))
MsgBox(taTestCon.Connection.ConnectionString)
Dim adapter As New dsTestConTableAdapters.tblTestTableAdapter
Dim conn As New SqlConnection()
Dim vrCompName As String = My.Computer.Name
conn.ConnectionString = "Data Source=" & vrCompName & "\SQLEXPRESS;AttachDbFilename=e:\dbTest.mdf;Integrated Security=True;User Instance=True"
adapter.Connection = conn
Dim table As DataTable = adapter.GetData()
MsgBox(adapter.Connection.ConnectionString)
ds = New dsTestCon()
adapter.Fill(ds.tblTest)
MsgBox(ds.tblTest.Rows(0).Item(1))