XML Connectionstrings

时间:2014-07-07 20:08:22

标签: database vb.net string connection

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
    <add name="Citrus_Welding.My.MySettings.CitWeldConnectionString"
        connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot;C:\Citrus           Welding\CitWeld.mdb&quot;"
        providerName="System.Data.OleDb" />
</connectionStrings>
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

我正在查看连接字符串,我需要数据源默认来自另一个页面的选定文件...我试过&amp; pagename.openfiledialog.filename&amp;但我不断收到错误。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您似乎希望用户能够在运行时设置Data Source。如果是,则从配置文件中的连接字符串中省略它,并在运行时将其设置为:

Dim builder As New OleDbConnectionStringBuilder(My.Settings.CitWeldConnectionString)

builder.DataSource = newDataSourceValue

Dim connection As New OleDbConnection(builder.ConnectionString)