ADO.NET对象的构造(1)_OleDbDataAdapter

类别:.NET开发 点击:0 评论:0 推荐:

OleDbDataAdapter 构造

n          Public Sub New()

n          Public Sub New(ByVal selectCommand As OleDbCommand)

n          Public Sub New(ByVal selectCommandText As String,ByVal selectConnection As OleDbConnection)

n          Public Sub New(ByVal selectCommandText As String,ByVal selectConnectionString As String)

 

参数

  1. selectCommand OleDbCommand,它是 SELECT 语句或存储过程,被设置为 OleDbDataAdapter SelectCommand 属性。
  2. selectCommandText 一个字符串,它是 SQL SELECT 语句或将由 OleDbDataAdapter SelectCommand 属性使用的存储过程。
  3. selectConnection 表示连接的 OleDbConnection
  4. selectConnectionString 连接字符串。

 

备注

当创建 OleDbDataAdapter 的实例时,下面的读/写属性将设置为以下初始值。

Properties

初始值

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

MissingSchemaAction.Add

 

可以通过单独调用属性来更改任何这些属性的值。

 

示例

Public Sub CreateOleDbDataAdapter()

    Dim myOleDbConnection As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")

 

Dim custDA As OleDbDataAdapter = New OleDbDataAdapter

 

Dim myOleDbCommand As OleDbCommand = New OleDbCommand("SELECT CustomerID, CompanyName FROM CUSTOMERS", myOleDbConnection)

Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(myOleDbCommand)

 

Dim mySelectText As String = "SELECT CustomerID, CompanyName FROM CUSTOMERS"

Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(mySelectText, myOleDbConnection)

 

Dim mySelectText As String = "SELECT CustomerID, CompanyName FROM CUSTOMERS"

Dim myConnString As String = "Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind"

Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(mySelectText, myConnString)

 

    custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey   

  

    custDA.SelectCommand = New OleDbCommand("SELECT CustomerID, CompanyName FROM CUSTOMERS", myOleDbConnection)

    custDA.InsertCommand = New OleDbCommand("INSERT INTO Customers (CustomerID, CompanyName) VALUES (?, ?)", myOleDbConnection)

    custDA.UpdateCommand = New OleDbCommand("UPDATE Customers SET CustomerID = ?, CompanyName = ? WHERE CustomerID = ?", myOleDbConnection)

    custDA.DeleteCommand = New OleDbCommand("DELETE FROM Customers WHERE CustomerID = ?", myOleDbConnection)

 

    custDA.InsertCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID")

    custDA.InsertCommand.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName")

 

    custDA.UpdateCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID")

    custDA.UpdateCommand.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName")

    custDA.UpdateCommand.Parameters.Add("@oldCustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

 

    custDA.DeleteCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

End Sub

 

(信息整理来自MSDN)

本文地址:http://com.8s8s.com/it/it45009.htm