添加
using System;
using System
using System
namespace ADONETWriteQuery
{
/**//// <summary>
/// Summary description for Class
/// </summary>
class Class
{
static void Main(string[] args)
{
string strDSN =
Source=c:\\mcTest
string strSQL =
// create Objects of ADOConnection and ADOCommand
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL
try
{
myConn
myCmd
}
catch (Exception e)
{
Console
}
finally
{
myConn
}
}
}
}
在具體講操作前
System
System
System
System
* SELECT操作!
下面是我的自己在寫測試程序的時候用到了
//通過ID得到當前留言詳細內容
public Notebook getNoteFromID(string noteid)
{
Notebook tempnote=new Notebook(); //定義返回值
try
{
OleDbConnection conn = getConn(); //getConn():得到連接對象
string strCom =
OleDbCommand myCommand =new OleDbCommand(strCom
conn
OleDbDataReader reader;
reader =myCommand
//下面把得到的值賦給tempnote對象
if(reader
{
tempnote
tempnote
ntent=reader[
tempnote
tempnote
tempnote
tempnote
tempnote
tempnote
}
else //如沒有該記錄
{
throw(new Exception(
}
reader
conn
}
catch(Exception e)
{
//throw(new Exception(
}
return(tempnote); //返回Databook對象
}
上面的程序就是通過OleDbDataReader來得到特定的記錄的!其中用到的語句我單獨寫到下面
OleDbConnection conn = getConn(); //getConn():得到連接對象
string strCom =
OleDbCommand myCommand =new OleDbCommand(strCom
conn
OleDbDataReader reader;
reader =myCommand
我在每句話後都加入了說明
我再列一個通過OleDbDataAdapter來得到記錄的例程
//Getlist():得到當前需要的留言列表
public DataView getNoteList()
{
DataView dataview;
System
try
{
OleDbConnection conn = getConn(); //getConn():得到連接對象
OleDbDataAdapter adapter = new OleDbDataAdapter();
string sqlstr=
mydataset= new System
adapter
adapter
conn
}
catch(Exception e)
{
throw(new Exception(
}
dataview = new DataView(mydataset
return(dataview);
}
這個程序或許有些復雜
OleDbConnection conn = getConn(); //通過函數getConn()得到連接對象
OleDbDataAdapter adapter = new OleDbDataAdapter(); //實例化OleDbDataAdapter對象
string sqlstr=
mydataset= new System
adapter
adapter
conn
在對上面的程序加一些補充說明
From:http://tw.wingwit.com/Article/program/net/201311/12651.html