.net+oracle+crystalReports開發web應用程式學習筆記(二)
來源:互聯網
上載者:User
上次提到基本的配置注意問題,現在開始實際開發oracle中的問題
一 oracle 資料庫的串連
但你裝了oracle的用戶端,在配置時就已經指定了資料庫伺服器,所以串連時主要由三個元素就可以串連上資料庫,資料庫的名稱(即SID),使用者名稱,密碼
SqlConnection con=new SqlConnection("Provider=MSDAORA.1;User ID=UserID;Data Source=xf;Password=password")
而sql Server不需要安裝用戶端,所以必須指定伺服器,和資料庫名
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中運行包(Package)中的函數和預存程序。
舉個例子,要運行下面一個sql語句:"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設計中(如設計sqlDataAdapter)不能夠直接使用包中的函數和預存程序,如果要使用,可以在設計時把包中要使用的函數和預存程序copy過來再設計時聲明一遍,就可以使用
2.在.net運行時直接添加代碼,系統會直接去尋中包中的內容
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();