OleDbConnectionStringBuilder.DataSource 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
연결할 데이터 원본의 이름을 가져오거나 설정합니다.
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. 이 속성은 연결 문자열 내의 "데이터 원본" 키에 해당합니다.