OdbcCommand Class
Assembly: System.Data (in system.data.dll)
The OdbcCommand class provides the following methods for executing commands against a data source:
| Item | Description |
|---|---|
| Executes commands that return rows. | |
| Executes commands such as SQL INSERT, DELETE, UPDATE, and SET statements. | |
| Retrieves a single value, for example, an aggregate value, from a database. |
You can reset the CommandText property and reuse the OdbcCommand object. However, you must close the OdbcDataReader before you can execute a new or previous command.
If execution of the command causes a fatal OdbcException such as a SQL Server severity level of 20 or more, OdbcConnection may close. However, the user can reopen the connection and continue.
The following example uses the ExecuteReader method of the OdbcCommand class, together with the OdbcDataReader and OdbcConnection classes, to select rows from a table.
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 Server 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
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.