直接贴代码哈哈哈,
public DataTable getInfo(int flag) { OracleConnection conn = null; DataSet ds = new DataSet(); try { string connString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.10.18)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)));Persist Security Info=True;User ID=zty65;Password=zty65;"; string sql = " select * from project where code='19/2015A6150' "; conn = new OracleConnection(connString); conn.Open(); OracleCommand cmd = new OracleCommand(sql, conn); OracleDataAdapter oda = new OracleDataAdapter(cmd); oda.Fill(ds); //OracleDataReader ord = cmd.ExecuteReader(); //while (ord.Read()) //{ // string aa = ord.GetOracleString(0).ToString(); // string bb = ord.GetOracleString(1).ToString(); // string cc = ord.GetOracleString(2).ToString(); // string dd = ord.GetOracleString(3).ToString(); //} } catch (Exception) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('读取数据失败!')", true); } finally { //关闭连接 conn.Close(); } DataTable dt = ds.Tables[0]; return dt; }