OleDbCommand 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 OleDbCommand 类的新实例。
重载
OleDbCommand() |
初始化 OleDbCommand 类的新实例。 |
OleDbCommand(String) |
使用查询的文本初始化 OleDbCommand 类的新实例。 |
OleDbCommand(String, OleDbConnection) |
使用查询的文本和 OleDbConnection 初始化 OleDbCommand 类的新实例。 |
OleDbCommand(String, OleDbConnection, OleDbTransaction) |
使用查询文本、OleDbConnection 以及 Transaction 初始化 OleDbCommand 类的新实例。 |
OleDbCommand()
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
初始化 OleDbCommand 类的新实例。
public:
OleDbCommand();
public OleDbCommand ();
Public Sub New ()
示例
以下示例创建 并 OleDbCommand 设置其一些属性。
public void CreateReader(string connectionString, string queryString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
command.CommandTimeout = 20;
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
reader.Close();
}
}
Public Sub CreateReader(ByVal connectionString As String, _
ByVal queryString As String)
Using connection As New OleDbConnection(connectionString)
Dim command As New OleDbCommand(queryString, connection)
command.CommandTimeout = 20
connection.Open()
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
Console.WriteLine(reader(0).ToString())
End While
reader.Close()
End Using
End Sub
注解
基构造函数将所有字段初始化为其默认值。 下表显示了 实例 OleDbCommand的初始属性值。
属性 | 初始值 |
---|---|
CommandText | 空字符串 (“”) |
CommandTimeout | 30 |
CommandType | Text |
Connection | null |
另请参阅
适用于
OleDbCommand(String)
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
使用查询的文本初始化 OleDbCommand 类的新实例。
public:
OleDbCommand(System::String ^ cmdText);
public OleDbCommand (string? cmdText);
public OleDbCommand (string cmdText);
new System.Data.OleDb.OleDbCommand : string -> System.Data.OleDb.OleDbCommand
Public Sub New (cmdText As String)
参数
- cmdText
- String
查询的文本。
示例
以下示例创建 并 OleDbCommand 设置其一些属性。
public void CreateMyOleDbCommand()
{
string queryString = "SELECT * FROM Categories ORDER BY CategoryID";
OleDbCommand command = new OleDbCommand(queryString);
command.CommandTimeout = 20;
}
Public Sub CreateMyOleDbCommand()
Dim queryString As String = "SELECT * FROM Categories ORDER BY CategoryID"
Dim command As New OleDbCommand(queryString)
command.CommandTimeout = 20
End Sub
注解
下表显示了 实例 OleDbCommand的初始属性值。
属性 | 初始值 |
---|---|
CommandText | cmdText |
CommandTimeout | 30 |
CommandType | Text |
Connection | null |
另请参阅
适用于
OleDbCommand(String, OleDbConnection)
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
使用查询的文本和 OleDbConnection 初始化 OleDbCommand 类的新实例。
public:
OleDbCommand(System::String ^ cmdText, System::Data::OleDb::OleDbConnection ^ connection);
public OleDbCommand (string? cmdText, System.Data.OleDb.OleDbConnection? connection);
public OleDbCommand (string cmdText, System.Data.OleDb.OleDbConnection connection);
new System.Data.OleDb.OleDbCommand : string * System.Data.OleDb.OleDbConnection -> System.Data.OleDb.OleDbCommand
Public Sub New (cmdText As String, connection As OleDbConnection)
参数
- cmdText
- String
查询的文本。
- connection
- OleDbConnection
表示到数据源的连接的 OleDbConnection。
示例
以下示例创建 并 OleDbCommand 设置其一些属性。
public void CreateReader(string connectionString, string queryString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
command.CommandTimeout = 20;
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
reader.Close();
}
}
Public Sub CreateReader(ByVal connectionString As String, _
ByVal queryString As String)
Using connection As New OleDbConnection(connectionString)
Dim command As New OleDbCommand(queryString, connection)
command.CommandTimeout = 20
connection.Open()
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
Console.WriteLine(reader(0).ToString())
End While
reader.Close()
End Using
End Sub
注解
下表显示了 实例 OleDbCommand的初始属性值。
属性 | 初始值 |
---|---|
CommandText | cmdText |
CommandTimeout | 30 |
CommandType | Text |
Connection | 一个新的 OleDbConnection ,它是 参数的值 connection 。 |
可以通过设置相关属性来更改其中任何参数的值。
另请参阅
适用于
OleDbCommand(String, OleDbConnection, OleDbTransaction)
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
- Source:
- OleDbCommand.cs
使用查询文本、OleDbConnection 以及 Transaction 初始化 OleDbCommand 类的新实例。
public:
OleDbCommand(System::String ^ cmdText, System::Data::OleDb::OleDbConnection ^ connection, System::Data::OleDb::OleDbTransaction ^ transaction);
public OleDbCommand (string? cmdText, System.Data.OleDb.OleDbConnection? connection, System.Data.OleDb.OleDbTransaction? transaction);
public OleDbCommand (string cmdText, System.Data.OleDb.OleDbConnection connection, System.Data.OleDb.OleDbTransaction transaction);
new System.Data.OleDb.OleDbCommand : string * System.Data.OleDb.OleDbConnection * System.Data.OleDb.OleDbTransaction -> System.Data.OleDb.OleDbCommand
Public Sub New (cmdText As String, connection As OleDbConnection, transaction As OleDbTransaction)
参数
- cmdText
- String
查询的文本。
- connection
- OleDbConnection
表示到数据源的连接的 OleDbConnection。
- transaction
- OleDbTransaction
OleDbCommand 在其中执行的事务。
示例
以下示例创建 并 OleDbCommand 设置其一些属性。
public void CreateReader(string connectionString, string queryString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
command.CommandTimeout = 20;
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
reader.Close();
}
}
Public Sub CreateReader(ByVal connectionString As String, _
ByVal queryString As String)
Using connection As New OleDbConnection(connectionString)
Dim command As New OleDbCommand(queryString, connection)
command.CommandTimeout = 20
connection.Open()
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
Console.WriteLine(reader(0).ToString())
End While
reader.Close()
End Using
End Sub
注解
下表显示了 实例 OleDbCommand的初始属性值。
属性 | 初始值 |
---|---|
CommandText | cmdText |
CommandTimeout | 30 |
CommandType | Text |
Connection | 一个新的 OleDbConnection ,它是 参数的值 connection 。 |
可以通过设置相关属性来更改其中任何参数的值。