OdbcCommand クラス
アセンブリ: System.Data (system.data.dll 内)
構文
OdbcCommand クラスには、データ ソースに対してコマンドを実行するための、次のメソッドがあります。
項目 | |
---|---|
ExecuteReader | |
ExecuteNonQuery | |
ExecuteScalar |
CommandText プロパティをリセットして、OdbcCommand オブジェクトを再利用できます。ただし、新規コマンドまたは以前のコマンドを実行する前に、OdbcDataReader を閉じる必要があります。
コマンドを実行した結果、致命的な OdbcException (SQL Server の重大度レベル 20 以上など) が発生した場合、OdbcConnection が閉じる可能性があります。ただし、ユーザーは接続を再び開いて、処理を継続できます。
OdbcCommand クラスの ExecuteReader メソッドを OdbcDataReader クラスおよび OdbcConnection クラスと共に使用して、テーブルから行を選択する例を次に示します。
Public Sub InsertRow(ByVal connectionString As String, _ ByVal insertSQL As String) Using connection As New OdbcConnection(connectionString) ' The insertSQL string contains a SQL statement that ' inserts a new row in the source table. Dim command As New OdbcCommand(insertSQL, connection) ' Open the connection and execute the insert command. Try connection.Open() command.ExecuteNonQuery() Catch ex As Exception Console.WriteLine(ex.Message) End Try ' The connection is automatically closed when the ' code exits the Using block. End Using End Sub
public void InsertRow(string connectionString, string insertSQL) { using (OdbcConnection connection = new OdbcConnection(connectionString)) { // The insertSQL string contains a SQL statement that // inserts a new row in the source table. OdbcCommand command = new OdbcCommand(insertSQL, connection); // Open the connection and execute the insert command. try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); } // The connection is automatically closed when the // code exits the using block. }
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DbCommand
System.Data.Odbc.OdbcCommand
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- OdbcCommand クラスのページへのリンク