oracle資料庫連接代碼
① oracle與.NET的資料庫連接代碼
應該對你有幫助
1. using System;
2.using System.Web;
3.using System.Web.UI;
4.using System.Web.UI.HtmlControls;
5.using System.Web.UI.WebControls;
6.using System.Data;
7.using System.Data.OracleClient;
8.public class pic2:Page {
9. public Label message;
10. public void Page_Load(Object sender,EventArgs e)
11. {
//設置連接字元串
12. string connstring="Data Source=eims;user=zbmis;password=zbmis;";
//實例化OracleConnection對象
13. OracleConnection conn=new OracleConnection(connstring);
14. try
15. {
16. conn.Open();
//實例化OracleCommand對象
17. OracleCommand cmd=conn.CreateCommand();
18. cmd.CommandText="select * from zbmis.OracleTypesTable";
19. OracleDataReader oracledatareader1=cmd.ExecuteReader();
//讀取數據
20. while (oracledatareader1.Read()) {
//讀取並顯示第一行第一列的數據
21. OracleString oraclestring1=oracledatareader1.GetOracleString(0);
22. Response.Write("OracleString " +oraclestring1.ToString());
//讀取並顯示第一行第二列的數據
23. OracleNumber oraclenumber1 =oracledatareader1.GetOracleNumber(1);
24. Response.Write("OracleNumber "+oraclenumber1.ToString());
//讀取並顯示第一行第三列的數據
25. OracleDateTime oracledatetime1=oracledatareader1.GetOracleDateTime(2);
26. Response.Write("OracleDateTime " +oracledatetime1.ToString());
//讀取並顯示第一行第四列的數據
27. OracleBinary oraclebinary1=oracledatareader1.GetOracleBinary(3);
28. if(oraclebinary1.IsNull==false)
29. {
30. foreach(byte b in oraclebinary1.Value)
31. {
32. Response.Write("byte " +b.ToString());
33. }
34. }
35. }
//釋放資源
36. oracledatareader1.Close();
37. }
38. catch(Exception ee)
39. {
//異常處理
40. message.Text=ee.Message;
41. }
42. finally
43. {
//關閉連接
44. conn.Close();
45. }
46. }
47.}