日期:2012-04-12  浏览次数:20372 次

n Overloads Public Overridable Function Add(ByVal value As Object) As Integer Implements IList.Add

n Overloads Public Function Add(ByVal parameterName As String,ByVal value As Object) As OleDbParameter

n Overloads Public Function Add(ByVal value As OleDbParameter) As OleDbParameter

n Overloads Public Function Add(ByVal parameterName As String,ByVal oleDbType As OleDbType) As OleDbParameter

n Overloads Public Function Add(ByVal parameterName As String,ByVal oleDbType As OleDbType,ByVal size As Integer) As OleDbParameter

n Overloads Public Function Add(ByVal parameterName As String,ByVal oleDbType As OleDbType,ByVal size As Integer,ByVal sourceColumn As String) As OleDbParameter




示例

Public Sub CreateOleDbParamColl(myConn As OleDbConnection)

Dim myCommand As OleDbCommand = New OleDbCommand("SELECT * FROM Customers WHERE CustomerID = ?", myConn)

Dim myParamCollection As OleDbParameterCollection = myCommand.Parameters



Dim myParm As Object = New OleDbParameter("CustomerID", OleDbType.VarChar)

Dim pIndex As Integer = myParamCollection.Add(myParm)



Dim myParm As OleDbParameter = myParamCollection.Add(New OleDbParameter("CustomerID", OleDbType.VarChar))



Dim myParm As OleDbParameter = myParamCollection.Add("CustomerID", “CustomerIDValue”);



Dim myParm As OleDbParameter = myParamCollection.Add("CustomerID", OleDbType.VarChar)



Dim myParm As OleDbParameter = myParamCollection.Add("CustomerID", OleDbType.VarChar, 5)



Dim myParm As OleDbParameter = myParamCollection.Add("CustomerID", OleDbType.VarChar, 5, "CustomerID")



End Sub



示例

Public Shared Function CreateCustomerAdapter(conn As OleDbConnection) As OleDbDataAdapter

Dim da As OleDbDataAdapter = New OleDbDataAdapter()

Dim cmd As OleDbCommand

Dim parm As OleDbParameter



' Create the SelectCommand.

cmd = New OleDbCommand("SELECT * FROM Customers WHERE Country = @Country AND City = @City", conn)

cmd.Parameters.Add("@Country", OleDbType.VarChar, 15)

cmd.Parameters.Add("@City", OleDbType.VarChar, 15)

da.SelectCommand = cmd



' Create the InsertCommand.

cmd = New OleDbCommand("INSERT INTO Customers (CustomerID, CompanyName) VALUES (@CustomerID, @CompanyName)", conn)

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

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

da.InsertCommand = cmd



' Create the DeleteCommand.

cmd = New OleDbCommand("DELETE FROM Customers WHERE CustomerID = @CustomerID", conn)

parm = cmd.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID")

parm.SourceVersion = DataRowVersion.Original

da.DeleteCommand = cmd



' Create the UpdateCommand.

cmd = New OleDbCommand("UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName WHERE CustomerID = @oldCustomerID", conn)

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

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

parm = cmd.Parameters.Add("@oldCustomerID", OleDbType.Char, 5, "CustomerID")

parm.SourceVersion = DataRowVersion.Original

da.UpdateCommand = cmd



Return da

End Function