上次提到基本的配置注意問(wèn)題,現(xiàn)在開(kāi)始實(shí)際開(kāi)發(fā)oracle中的問(wèn)題
一 oracle 數(shù)據(jù)庫(kù)的連接
但你裝了oracle的客戶端,在配置時(shí)就已經(jīng)指定了數(shù)據(jù)庫(kù)服務(wù)器,所以連接時(shí)主要由三個(gè)元素就可以連接上數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)的名稱(即SID),用戶名,密碼
SqlConnection con=new SqlConnection("Provider=MSDAORA.1;User ID=UserID;Data Source=xf;Password=password")
而sql Server不需要安裝客戶端,所以必須指定服務(wù)器,和數(shù)據(jù)庫(kù)名
SqlConnection con=new SqlConnection("workstation id=XIAOFENG;packet size=4096;user id=sa;integrated security=SSPI;data source=xiaofeng;persist security info=False;initial catalog=xf");
二 在oracle中運(yùn)行包(Package)中的函數(shù)和存儲(chǔ)過(guò)程。
舉個(gè)例子,要運(yùn)行下面一個(gè)sql語(yǔ)句:"select order_no,inventory_part_api.get_description(contract,part_no),part_no from SHOP_ORD where inventory_part_api.get_description(contract,part_no) like '%喜之郎25%果凍%'";
1.在.net設(shè)計(jì)中(如設(shè)計(jì)sqlDataAdapter)不能夠直接使用包中的函數(shù)和存儲(chǔ)過(guò)程,如果要使用,可以在設(shè)計(jì)時(shí)把包中要使用的函數(shù)和存儲(chǔ)過(guò)程copy過(guò)來(lái)再設(shè)計(jì)時(shí)聲明一遍,就可以使用
2.在.net運(yùn)行時(shí)直接添加代碼,系統(tǒng)會(huì)直接去尋中包中的內(nèi)容
string strCommand;
strCommand="select order_no,inventory_part_api.get_description(contract,part_no),part_no from SHOP_ORD where inventory_part_api.get_description(contract,part_no) like '%喜之郎25%果凍%'";
OleDbConnection con=new OleDbConnection("Provider=MSDAORA.1;Password=password;User ID=UserID;Data Source=xf");
con.Open();
OleDbDataAdapter adapter=new OleDbDataAdapter(strCommand,con);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
this.DataGrid1.DataSource=dataset;
DataGrid1.DataBind();
con.Close();
3.怎么使用存儲(chǔ)過(guò)程
OracleConnection conn = new OracleConnection("Data Source=Oracle8i;Integrated Security=yes");
Conn.Open;
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "sp_pkg.getdata";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new OracleParameter("a1", OracleType.Cursor)).Direction = ParameterDirection.Output;
cmd.Parameters.Add(new OracleParameter("a2", OracleType.Cursor)).Direction = ParameterDirection.Output;
DataSet ds = new DataSet();
OracleDataAdapter adapter = new OracleDataAdapter(cmd);
adapter.Fill(ds);
|
溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!