Public NotInheritable Class OdbcCommand Inherits DbCommand Implements ICloneable
Dim instance As OdbcCommand
public sealed class OdbcCommand : DbCommand, ICloneable
public ref class OdbcCommand sealed : public DbCommand, ICloneable
public final class OdbcCommand extends DbCommand implements ICloneable
OdbcCommand 类提供下列对数据源执行命令的方法:
项
说明
ExecuteReader
执行返回行的命令。
ExecuteNonQuery
执行 SQL INSERT、DELETE、UPDATE 和 SET 语句等命令。
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. }
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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。