写道
OracleConnection thisConnection = new OracleConnection();
thisConnection.ConnectionString = @"Data Source=gxmis;Persist Security Info=True;User ID=system;Password=admin";
try
{
thisConnection.Open();
OracleDataAdapter thisAdapter = new OracleDataAdapter("select * from student", thisConnection);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet,"student");
foreach (DataRow theRow in thisDataSet.Tables["student"].Rows)
{
Console.WriteLine(theRow["student_id"] + "\t" +theRow["student_name"] );
}
thisConnection.Close();
}
catch (OracleException oe)
{
Console.WriteLine("数据库连接失败");
Console.WriteLine(oe.Message);
}
thisConnection.ConnectionString = @"Data Source=gxmis;Persist Security Info=True;User ID=system;Password=admin";
try
{
thisConnection.Open();
OracleDataAdapter thisAdapter = new OracleDataAdapter("select * from student", thisConnection);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet,"student");
foreach (DataRow theRow in thisDataSet.Tables["student"].Rows)
{
Console.WriteLine(theRow["student_id"] + "\t" +theRow["student_name"] );
}
thisConnection.Close();
}
catch (OracleException oe)
{
Console.WriteLine("数据库连接失败");
Console.WriteLine(oe.Message);
}
本文提供了一个使用C#连接Oracle数据库并查询学生信息的示例代码。该示例展示了如何创建OracleConnection对象、设置连接字符串、执行SQL查询以及处理查询结果。
1068

被折叠的 条评论
为什么被折叠?



