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)
参数
备注
当创建 OleDbDataAdapter 的实例时,下面的读/写属性将设置为以下初始值。
Properties |
初始值 |
MissingMappingAction.Passthrough | |
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