|
DataAdapter對象含有四個不同的操作命令,分別如下:
(1)、SelectCommand:用來或去數(shù)據(jù)源中的記錄;
(2)、InsertCommand:用來向數(shù)據(jù)源中新插入一條記錄;
(3)、UpdateCommand:用來更新數(shù)據(jù)源中的數(shù)據(jù);
(4)、DeleteCommand:用來刪除數(shù)劇源中的記錄。
根據(jù)使用的數(shù)據(jù)庫不同,DataAdapter也具有了兩個不同的對象:OleDbDataReader和SqlDataReader對象,分別用來訪問支持ADO Managed Provider的數(shù)據(jù)庫和SQL Server數(shù)據(jù)庫。
當(dāng)使用OleDbDataReader對象時,使用方法:
[Visual Basic語言]
Public Function SelectOleDbSrvRows(dataSet As DataSet, connection As String, query As String) As DataSet
Dim conn As New OleDbConnection(connection)
Dim adapter As New OleDbDataAdapter()
adapter.SelectCommand = new OleDbCommand(query, conn)
adapter.Fill(dataset)
Return dataset
End Function
[C#語言]
public DataSet SelectOleDbSrvRows(DataSet dataset,string connection,string query)
{
OleDbConnection conn = new OleDbConnection(connection);
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(query, conn);
adapter.Fill(dataset);
return dataset;
}
當(dāng)使用SqlDataReaderd對象時,使用方法為:
[Visual Basic語言]
Public Function SelectSqlSrvRows(dataSet As DataSet, connection As String, query As String) As DataSet
Dim conn As New SqlConnection(connection)
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = new SqlCommand(query, conn)
adapter.Fill(dataset)
Return dataset
End Function
[C#語言]
public DataSet SelectSqlSrvRows(DataSet dataset,string connection,string query)
{
SqlConnection conn = new SqlConnection(connection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(query, conn);
adapter.Fill(dataset);
return dataset;
}
AspNet技術(shù):ASP.NET:ADO.NET的DataAdapter對象,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。