SqlDataSource コンストラクタ ()とは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SqlDataSource コンストラクタ ()の意味・解説 

SqlDataSource コンストラクタ ()


SqlDataSource コンストラクタ (String, String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

接続文字列SELECT コマンド指定して、SqlDataSource クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    connectionString As String, _
    selectCommand As String _
)
Dim connectionString As String
Dim selectCommand As String

Dim instance As New SqlDataSource(connectionString,
 selectCommand)
public SqlDataSource (
    string connectionString,
    string selectCommand
)
public:
SqlDataSource (
    String^ connectionString, 
    String^ selectCommand
)
public SqlDataSource (
    String connectionString, 
    String selectCommand
)
public function SqlDataSource (
    connectionString : String, 
    selectCommand : String
)

パラメータ

connectionString

基になるデータベース接続するために使用する接続文字列

selectCommand

基になるデータベースからデータ取得するために使用する SQL クエリSQL クエリパラメータ化された SQL 文字列場合、SelectParameters コレクションへの Parameter オブジェクト追加必要になることがあります

解説解説

異なデータベース製品では異な種類SQL使用されるため、selectCommand構文は、現在使用されている ADO.NET プロバイダによって異なります。このプロバイダは、ProviderName プロパティによって示されます。SQL 文字列パラメータ化されたクエリまたはコマンドである場合パラメータのプレースホルダは、使用されている ADO.NET プロバイダ依存します。たとえば、プロバイダSqlDataSource クラス既定プロバイダである System.Data.SqlClient の場合パラメータのプレースホルダは '@parameterName' です。ただし、プロバイダが System.Data.Odbc または System.Data.OleDb に設定されている場合パラメータのプレースホルダは '?' となりますパラメータ化された SQL クエリコマンド詳細については、「SqlDataSource コントロールにおけるパラメータ使用」を参照してください

データ ソースストアド プロシージャサポートしている場合、SelectCommand 値には、SQL 文字列またはストアド プロシージャの名前を指定できます

使用例使用例

SqlDataSource コンストラクタ使用して SqlDataSource コントロール作成する方法次のコード例示します。この例は、Web フォーム ページ上にない SqlDataSource コントロール使用されている点が例外的ですが、中間層オブジェクト実装において、データベース対話する簡単な方法としてビジネス オブジェクト使用されています。この例では、Web.config ファイル格納され接続文字列使用します

このコード例は、ObjectDataSource クラストピック取り上げているコード例一部分です。

' Returns a collection of NorthwindEmployee objects.
Public Shared Function GetAllEmployees()
 As ICollection
   Dim al As New ArrayList()

   Dim cts As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("NorthwindConnection")
   Dim sds As New SqlDataSource(cts.ConnectionString,
 "SELECT EmployeeID FROM Employees")
   Try
      Dim IDs As IEnumerable = sds.Select(DataSourceSelectArguments.Empty)

      ' Iterate through the Enumeration and create a
      ' NorthwindEmployee object for each ID.
      For Each row As DataRowView
 In IDs
         Dim id As String
 = row("EmployeeID").ToString()
         Dim nwe As New
 NorthwindEmployee(id)
         ' Add the NorthwindEmployee object to the collection.
         al.Add(nwe)
      Next
   Finally
      ' If anything strange happens, clean up.
      sds.Dispose()
   End Try

   Return al
End Function 'GetAllEmployees
// Returns a collection of NorthwindEmployee objects.
public static ICollection GetAllEmployees ()
 {
  ArrayList al = new ArrayList();

  ConnectionStringSettings cts = ConfigurationManager.ConnectionStrings["NorthwindConnection"];

  SqlDataSource sds
    = new SqlDataSource(cts.ConnectionString, "SELECT EmployeeID
 FROM Employees");

  try {

    IEnumerable IDs = sds.Select(DataSourceSelectArguments.Empty);

    // Iterate through the Enumeration and create a
    // NorthwindEmployee object for each ID.
    foreach (DataRowView row in IDs) {
      string id = row["EmployeeID"].ToString();
      NorthwindEmployee nwe = new NorthwindEmployee(id);
      // Add the NorthwindEmployee object to the collection.
      al.Add(nwe);
    }
  }
  finally {
    // If anything strange happens, clean up.
    sds.Dispose();
  }

  return al;
}
// Returns a collection of NorthwindEmployee objects.
public static ICollection GetAllEmployees()
    throws NorthwindDataException, SqlException
{
    ArrayList al = new ArrayList();

    ConnectionStringSettings cts = 
        ConfigurationManager.get_ConnectionStrings().get_Item("NorthwindConnection");

    
    SqlDataSource sds =
        new SqlDataSource(cts.get_ConnectionString(), "SELECT
 EmployeeID FROM Employees");

    try {
        IEnumerable ids = sds.Select(DataSourceSelectArguments.get_Empty());

        // Iterate through the Enumeration and create a
        // NorthwindEmployee object for each id.
        IEnumerator enumerator = ids.GetEnumerator();
        while (enumerator.MoveNext()) {
            // The IEnumerable contains DataRowView objects.
            DataRowView row = (DataRowView)enumerator.get_Current();
            String id = row.get_Item("EmployeeID").ToString();
            NorthwindEmployee nwe = new NorthwindEmployee(id);
            // Add the NorthwindEmployee object to the collection.
            al.Add(nwe);
        }
    }
    finally {
        // If anything strange happens, clean up.
        sds.Dispose();
    }

    return al;
} //GetAllEmployees
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlDataSource クラス
SqlDataSource メンバ
System.Web.UI.WebControls 名前空間
ConnectionString
SelectCommand
SelectParameters

SqlDataSource コンストラクタ


SqlDataSource コンストラクタ (String, String, String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

接続文字列SELECT コマンド指定してSqlDataSource クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    providerName As String, _
    connectionString As String, _
    selectCommand As String _
)
Dim providerName As String
Dim connectionString As String
Dim selectCommand As String

Dim instance As New SqlDataSource(providerName,
 connectionString, selectCommand)
public SqlDataSource (
    string providerName,
    string connectionString,
    string selectCommand
)
public:
SqlDataSource (
    String^ providerName, 
    String^ connectionString, 
    String^ selectCommand
)
public SqlDataSource (
    String providerName, 
    String connectionString, 
    String selectCommand
)
public function SqlDataSource (
    providerName : String, 
    connectionString : String, 
    selectCommand : String
)

パラメータ

providerName

SqlDataSource が使用するデータ プロバイダの名前。プロバイダ設定されていない場合SqlDataSourceMicrosoft SQL ServerADO.NET プロバイダ既定使用します

connectionString

基になるデータベース接続するために使用する接続文字列

selectCommand

基になるデータベースからデータ取得するために使用する SQL クエリSQL クエリパラメータ化された SQL 文字列場合、SelectParameters コレクションへの Parameter オブジェクト追加必要になることがあります

解説解説

異なデータベース製品では異な種類SQL使用されるため、selectCommand構文は、現在使用されている ADO.NET プロバイダによって異なります。このプロバイダは、providerName パラメータによって示されます。SQL 文字列パラメータ化されたクエリまたはコマンドである場合パラメータのプレースホルダは、使用されている ADO.NET プロバイダ依存します。たとえば、プロバイダSqlDataSource クラス既定プロバイダである System.Data.SqlClient の場合パラメータのプレースホルダは '@parameterName' です。ただし、プロバイダが System.Data.Odbc または System.Data.OleDb に設定されている場合パラメータのプレースホルダは '?' となりますパラメータ化された SQL クエリコマンド詳細については、「SqlDataSource コントロールにおけるパラメータ使用」を参照してください

データ ソースストアド プロシージャサポートしている場合、SelectCommand プロパティには、SQL 文字列またはストアド プロシージャの名前を指定できます

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlDataSource クラス
SqlDataSource メンバ
System.Web.UI.WebControls 名前空間
ProviderName
ConnectionString
SelectCommand
SelectParameters



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SqlDataSource コンストラクタ ()」の関連用語

SqlDataSource コンストラクタ ()のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SqlDataSource コンストラクタ ()のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS