日期:2014-05-17 浏览次数:20776 次
//连接字符串
//string connectionString = "Data Source=orcl;User ID=sys;Password=sys;Unicode=True";
string connectionString = "Data Source=orcl;User ID=scott;Password=scott;Unicode=True";
//创建Oracle连接对象
OracleConnection con = new OracleConnection(connectionString);
//打开连接
con.Open();
//建立Sql查询语句
string sql = "select * from emp";
//创建Oracle命令行对象
OracleCommand cmd = new OracleCommand(sql, con);
//执行命令行对象
OracleDataReader odr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
IList<UserInfo> users = new List<UserInfo>();
while (odr.Read())
{
UserInfo user = new UserInfo();
user.UserID = Convert.ToInt32(odr["EMPNO"]);
user.UserName = Convert.ToString(odr["ENAME"]);
user.UserAge = Convert.ToString(odr["sal"]);
users.Add(user);
}
//绑定DataGridView控件
dataGridView1.DataSource = users;
//string connectionString = "Data Source=orcl;User ID=sys;Password=sys;Unicode=True";