DataAdapter對象含有四個(gè)不同的操作命令,分別如下:
(1)、SelectCommand:用來或去數(shù)據(jù)源中的記錄;
(2)、InsertCommand:用來向數(shù)據(jù)源中新插入一條記錄;
(3)、UpdateCommand:用來更新數(shù)據(jù)源中的數(shù)據(jù);
(4)、DeleteCommand:用來刪除數(shù)劇源中的記錄。
根據(jù)使用的數(shù)據(jù)庫不同,DataAdapter也具有了兩個(gè)不同的對象:OleDbDataReader和SqlDataReader對象,分別用來訪問支持ADO Managed Provider的數(shù)據(jù)庫和SQL Server數(shù)據(jù)庫。
當(dāng)使用OleDbDataReader對象時(shí),使用方法:
[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對象時(shí),使用方法為:
[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;
}
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com