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

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

SqlCommand コンストラクタ ()

SqlCommand クラス新しインスタンス初期化します。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

public SqlCommand ()
public:
SqlCommand ()
public SqlCommand ()
解説解説
使用例使用例

SqlCommand作成し、その CommandTimeout プロパティ設定する例を次に示します

Public Sub CreateSqlCommand()
    Dim command As New SqlCommand()
    command.CommandTimeout = 15
    command.CommandType = CommandType.Text
End Sub
public void CreateSqlCommand() 
{
   SqlCommand command = new SqlCommand();
   command.CommandTimeout = 15;
   command.CommandType = CommandType.Text;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlCommand コンストラクタ (String, SqlConnection, SqlTransaction)

クエリ テキストSqlConnection、および SqlTransaction指定してSqlCommand クラス新しインスタンス初期化します。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub New ( _
    cmdText As String, _
    connection As SqlConnection, _
    transaction As SqlTransaction _
)
Dim cmdText As String
Dim connection As SqlConnection
Dim transaction As SqlTransaction

Dim instance As New SqlCommand(cmdText,
 connection, transaction)
public SqlCommand (
    string cmdText,
    SqlConnection connection,
    SqlTransaction transaction
)
public:
SqlCommand (
    String^ cmdText, 
    SqlConnection^ connection, 
    SqlTransaction^ transaction
)
public SqlCommand (
    String cmdText, 
    SqlConnection connection, 
    SqlTransaction transaction
)
public function SqlCommand (
    cmdText : String, 
    connection : SqlConnection, 
    transaction : SqlTransaction
)

パラメータ

cmdText

クエリ テキスト

connection

SQL Serverインスタンスへの接続を表す SqlConnection。

transaction

SqlCommand の実行対象の SqlTransaction。

解説解説

SqlCommandインスタンス初期プロパティ値を次の表に示します

プロパティ

初期値

CommandText

cmdText

CommandTimeout

30

CommandType

CommandType.Text

Connection

connection パラメータの値である新しSqlConnection

これらのパラメータの値は、関連するプロパティ設定することによって変更できます

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlCommand コンストラクタ (String, SqlConnection)

クエリ テキストSqlConnection指定して、SqlCommand クラス新しインスタンス初期化します。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub New ( _
    cmdText As String, _
    connection As SqlConnection _
)
Dim cmdText As String
Dim connection As SqlConnection

Dim instance As New SqlCommand(cmdText,
 connection)
public SqlCommand (
    string cmdText,
    SqlConnection connection
)
public:
SqlCommand (
    String^ cmdText, 
    SqlConnection^ connection
)
public SqlCommand (
    String cmdText, 
    SqlConnection connection
)
public function SqlCommand (
    cmdText : String, 
    connection : SqlConnection
)

パラメータ

cmdText

クエリ テキスト

connection

SQL Serverインスタンスへの接続を表す SqlConnection。

解説解説

SqlCommandインスタンス初期プロパティ値を次の表に示します

プロパティ

初期値

CommandText

cmdText

CommandTimeout

30

CommandType

CommandType.Text

Connection

connection パラメータの値である新しSqlConnection

これらのパラメータの値は、関連するプロパティ設定することによって変更できます

使用例使用例

SqlCommand作成し、そのプロパティ一部設定する例を次に示します

Public Sub CreateCommand(ByVal
 queryString As String, _
  ByVal connectionString As String)
    Using connection As New SqlConnection(connectionString)
        Dim command As New
 SqlCommand(queryString, connection)

        connection.Open()
        Dim reader As SqlDataReader = command.ExecuteReader()
            While reader.Read()
            Console.WriteLine(String.Format("{0},
 {1}", _
                reader(0), reader(1)))
        End While
    End Using
End Sub
private static void CreateCommand(string
 queryString,
    string connectionString)
{
    using (SqlConnection connection = new SqlConnection(
               connectionString))
    {
        SqlCommand command = new SqlCommand(
            queryString, connection);
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0}, {1}",
                reader[0], reader[1]));
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlCommand コンストラクタ (String)

クエリ テキスト指定して、SqlCommand クラス新しインスタンス初期化します。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub New ( _
    cmdText As String _
)
Dim cmdText As String

Dim instance As New SqlCommand(cmdText)
public SqlCommand (
    string cmdText
)
public:
SqlCommand (
    String^ cmdText
)
public SqlCommand (
    String cmdText
)
public function SqlCommand (
    cmdText : String
)

パラメータ

cmdText

クエリ テキスト

解説解説
使用例使用例

接続文字列コマンド テキスト渡してSqlCommand作成する例を次に示します

Public Sub CreateCommand()
    Dim queryString As String
 = "SELECT * FROM Categories ORDER BY CategoryID"
    Dim command As New SqlCommand(queryString)
    command.CommandTimeout = 15
    command.CommandType = CommandType.Text
End Sub 
public void CreateCommand() 
 {
    string queryString = "SELECT * FROM Categories ORDER
 BY CategoryID";
    SqlCommand command = new SqlCommand(queryString);
    command.CommandTimeout = 15;
    command.CommandType = CommandType.Text;
 }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlCommand コンストラクタ

SqlCommand クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

SqlCommand クラス
SqlCommand メンバ
System.Data.SqlClient 名前空間

その他の技術情報

ADO.NET でのデータへの接続およびデータ取得
.NET Framework Data Provider for SQL Server使用



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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2024 GRAS Group, Inc.RSS