OdbcCommand クラスとは? わかりやすく解説

OdbcCommand クラス

データ ソースに対して実行する SQL ステートメントまたはストアド プロシージャ表します。このクラス継承できません。

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

Public NotInheritable Class
 OdbcCommand
    Inherits DbCommand
    Implements ICloneable
public sealed class OdbcCommand : DbCommand,
 ICloneable
public ref class OdbcCommand sealed : public
 DbCommand, ICloneable
public final class OdbcCommand extends DbCommand
 implements ICloneable
public final class OdbcCommand extends
 DbCommand implements ICloneable
解説解説

OdbcCommand クラスには、データ ソースに対してコマンド実行するための、次のメソッドあります

項目

説明

ExecuteReader

行を返すコマンド実行します

ExecuteNonQuery

SQLINSERTDELETEUPDATESET ステートメントなどのコマンド実行します

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.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Data.Common.DbCommand
        System.Data.Odbc.OdbcCommand
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
OdbcCommand メンバ
System.Data.Odbc 名前空間
OdbcDataAdapter
OdbcConnection
その他の技術情報
Executing a Command



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

辞書ショートカット

すべての辞書の索引

「OdbcCommand クラス」の関連用語

OdbcCommand クラスのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS