编辑连接字符串时出错 [英] Error While editing Connection string

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

问题描述


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

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

推荐答案

您确定dbSQLServerTestDataSet1.tblContact是一个类吗?它看起来更像是具有属性(tblContact)的实例(dbSQLServerTestDataSet1).

New需要一个类名,而不是一个实例.
Are you sure that dbSQLServerTestDataSet1.tblContact is a class? It looks a lot more like an instance (dbSQLServerTestDataSet1) with a property (tblContact).

New requires a class name, not an instance.


在名称空间中添加
Add in the namespace
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))


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆