转载from:http://www.cnblogs.com/gguozhenqian/p/4262813.html
操作步骤:
- DLL下载后并引用
下载地址:Oracle.ManagedDataAccess.zip 下载后,将Oracle.ManagedDataAccess.dll放到自己的项目中,然后引用
- 直接调用(connString 改为自己的连接字符串)
using Oracle.ManagedDataAccess.Client;
public static string ConnectOracle()
{
try
{
string connString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=130.147.246.144)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ECMS)));Persist Security Info=True;User ID=system;Password=Service01;";
OracleConnection con = new OracleConnection(connString);
con.Open();
return string.Empty;
}
catch (Exception ex)
{
return ex.ToString();
}
}
- 传参查询
string sql="select * from table1 where Code=:code";
string code=TextBox1.Text;
string connstring ="你的connString(如第二点)";
OracleConnection conn = new OracleConnection(connstring);
conn.Open();
OracleCommand cmd = new OracleCommand(sql,conn);
cmd.Parameters.Add(new OracleParameter(":code",code));
OracleDataAdapter oradap = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
oradap.Fill(ds);
DataTable tb = ds.Tables[0];
ASPxGridView1.DataSource = tb;
ASPxGridView1.DataBind();
//ASPxGridView 是DEV控件,也可绑定GridView
|
请发表评论