实现一个简单的用户登陆,数据来自Oracle数据库,代码如下,执行到readOracleDataReader reader = cmd.ExecuteReader()
时出错。
单步看过用户名和密码都是正确的,哪里有问题呢?新手求教。
protected void Button1_Click(object sender, EventArgs e) { String username = UserName.Text.ToString(); String password = Password.Text.ToString(); String queryString = "select CZR_MM,CZR_XM from T_BYSQ_BJSH_SKB_CZR where CZR_XM=@UserName and CZR_MM=@Password"; // string connString = "DATA SOURCE=orcl;PERSIST SECURITY INFO=True;USER ID=SCOTT;password=admin"; String connString = ConfigurationManager.ConnectionStrings["ConnectionStringUseOracleClient"].ToString(); OracleConnection conn = new OracleConnection(connString);//连接oracle数据库 try { conn.Open();//打开数据库,以便下面的操作 Response.Write("数据库打开成功<br>"); OracleCommand cmd= new OracleCommand();//创建一个OracleCommand对象,以便用它执行一个的语句/存储过程 Response.Write("cmd对象创建成功<br>"); cmd.Connection = conn; cmd.CommandText = queryString; cmd.Parameters.Add(new OracleParameter("@UserName",username)); cmd.Parameters.Add(new OracleParameter("@Password", password)); OracleDataReader reader = cmd.ExecuteReader(); Response.Write("执行成功<br>"); Response.Write(reader); Response.Write("连接成功<br>"); } catch (Exception ex) { Response.Write("连接失败"); } finally { conn.Close(); } }
付费偷看金额在0.1-10元之间
一周热门 更多>