本人在c#.net中建立了个windows应用程序。现在要用他连接个ORACLE总不太成功。
有高手能写个能用的给我吗?我发下我写的大家指正下。
private void Form1_Load(object sender, System.EventArgs e)
{ try
{
string ConnectionString="User ID=sang;Data Source='oracle_10.40.18.24';Password=sang;";//写连接串
OracleConnection conn=new oracleConnection(ConnectionString);
//connection = new OracleConnection("User ID=sang;Data Source='oracle_10.40.18.24';Password=sang;"); //Provider="MSDAORA.1";User ID=sang;Data Source="oracle_10.40.18.24";Password=sang
//写连接串
//OracleDataAdapter dataAdapter = new OracleDataAdapter("select * from TEXT",connection);
//创建一个新连接 conn.Open(); OracleCommand cmd = conn.CreateCommand();
cmd.CommandText="select * from TEXT";
//在这儿写sql语句
OracleDataReader odr=cmd.ExecuteReader();
//创建一个OracleDateReader对象
//
// this.comboBox1.DataSource = odr;
// this.comboBox1.DisplayMember = "guojia";
// this.comboBox1.ValueMember = "guojia";
//// this.comboBox1.DataBindings;
//
// while(odr.Read())
// //读取数据,如果odr.Read()返回为false的话,就说明到记录集的尾部了
// {
// Response.Write(odr.GetOracleString(1).ToString());
// //输出字段1,这个数是字段索引
// }
odr.Close();
}
catch(Exception ex)
{
MessageBox.Show("e"); }
finally
{
conn.Close(); //关闭连接
}
}
有高手能写个能用的给我吗?我发下我写的大家指正下。
private void Form1_Load(object sender, System.EventArgs e)
{ try
{
string ConnectionString="User ID=sang;Data Source='oracle_10.40.18.24';Password=sang;";//写连接串
OracleConnection conn=new oracleConnection(ConnectionString);
//connection = new OracleConnection("User ID=sang;Data Source='oracle_10.40.18.24';Password=sang;"); //Provider="MSDAORA.1";User ID=sang;Data Source="oracle_10.40.18.24";Password=sang
//写连接串
//OracleDataAdapter dataAdapter = new OracleDataAdapter("select * from TEXT",connection);
//创建一个新连接 conn.Open(); OracleCommand cmd = conn.CreateCommand();
cmd.CommandText="select * from TEXT";
//在这儿写sql语句
OracleDataReader odr=cmd.ExecuteReader();
//创建一个OracleDateReader对象
//
// this.comboBox1.DataSource = odr;
// this.comboBox1.DisplayMember = "guojia";
// this.comboBox1.ValueMember = "guojia";
//// this.comboBox1.DataBindings;
//
// while(odr.Read())
// //读取数据,如果odr.Read()返回为false的话,就说明到记录集的尾部了
// {
// Response.Write(odr.GetOracleString(1).ToString());
// //输出字段1,这个数是字段索引
// }
odr.Close();
}
catch(Exception ex)
{
MessageBox.Show("e"); }
finally
{
conn.Close(); //关闭连接
}
}
解决方案 »
- 下面的代码怎么实现不了我想要的那个点击datagridview中任意一行,把该行的值对应用textBox显示呢?
- form登陆SQL问题
- VS2010 数据库连接不上
- listview 取值
- 那位大哥能提供一下C#FORM程序的下载,要开源的哦
- sql超难问题~~~
- 难那,想做新的TextBox,不知如何下手
- C#如何用类名创建类对象(急)
- 遗弃Java和C#,intel拥抱“IT语言”
- webKitBrowser1.Navigate("www.taobao.com")不能跳转到淘宝界面
- 07应届毕业的程序员该何去何从?请大家近来讨论一下?给个意见和建议?(我没学到东西)
- 嗯!学到DataGrid了!
catch(Exception ex)
{
MessageBox.Show(ex.Message);}
把异常的内容贴出来啊
OracleConnection conn = new OracleConnection(_connectionString);
conn.Open();//上面是我常用的连接方式
external dbid length 18 is greater than maximum (16)--最大长度16位,你定义了18位
--改称短点的名字测试一下
Action: Report the problem to your external transaction coordinator vendor.