编辑连接字符串时出错

编辑连接字符串时出错

本文介绍了编辑连接字符串时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用以下代码来编辑我的连接字符串

Hi,
I am using following code to edit my connection string

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部分上.这些对象确实在我的项目中退出.我也进口了



But it gives error on Dim adapter As New dbSQLServerTestDataSet1.tblContact

on dbSQLServerTestDataSet1.tblContact part of the line. These objects do exits in my project. I have also imported

Imports System.Data
Imports System.Data.SqlClient



请指导.
感谢



Please guide.
Thanks

推荐答案


Imports System.Data.SqlClient


然后使用以下代码:


then use following code:

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))


这篇关于编辑连接字符串时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 21:00