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.}