OleDbConnectionStringBuilder.DataSource プロパティ

定義

接続先のデータ ソースの名前を取得または設定します。

public:
 property System::String ^ DataSource { System::String ^ get(); void set(System::String ^ value); };
public string DataSource { get; set; }
member this.DataSource : string with get, set
Public Property DataSource As String

プロパティ値

DataSource プロパティの値。値が指定されていない場合は String.Empty

次のコンソール アプリケーションの例では、新OleDbConnectionStringBuilderしいインスタンスを作成し、 プロパティと Provider プロパティをDataSource設定します。 最後に、この例では新 OleDbConnection しいインスタンスを作成し、そのオブジェクトを使用して、指定されたデータ ストアに接続します。

using System.Data.OleDb;

class Program
{
    static void Main()
    {
        OleDbConnectionStringBuilder builder =
            new OleDbConnectionStringBuilder();
        builder.DataSource = @"C:\Sample.mdb";
        builder.Provider = "Microsoft.Jet.Oledb.4.0";
        Console.WriteLine(builder.ConnectionString);

        // This sample assumes that you have a database named
        // C:\Sample.mdb available.
        using (OleDbConnection connection = new
                   OleDbConnection(builder.ConnectionString))
        {
            try
            {
                connection.Open();
                // Do something with the database here.
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        Console.WriteLine("Press Enter to finish.");
        Console.ReadLine();
    }
}
Imports System.Data.OleDb

Module Module1
    Sub Main()
        Dim builder As New OleDbConnectionStringBuilder()
        builder.DataSource = "C:\Sample.mdb"
        builder.Provider = "Microsoft.Jet.Oledb.4.0"
        Console.WriteLine(builder.ConnectionString)

        ' This sample assumes that you have a database named
        ' C:\Sample.mdb available.
        Using connection As New OleDbConnection(builder.ConnectionString)
            Try
                connection.Open()
                ' Do something with the database here.
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try
        End Using

        Console.WriteLine("Press Enter to finish.")
        Console.ReadLine()
    End Sub
End Module

注釈

このプロパティの設定を試行した際に、渡された値が null である場合、DataSource プロパティはリセットされます。 値が設定されておらず、開発者が プロパティの取得を試みる場合、戻り値は です String.Empty。 このプロパティは、接続文字列内の "データ ソース" キーに対応します。

適用対象

こちらもご覧ください