熟悉asp.net与oralce连接的进来帮个忙
string query= "select count(*) from tbl_admin where username=@username and password=@password ";
objconnection=new OracleConnection(ConfigurationSettings.AppSettings[ "CnStirng "]);
OracleCommand objcommand=new OracleCommand(query,objconnection);
objcommand.Parameters.Add( "@username ",OracleType.VarChar,10);
objcommand.Parameters .Add( "@password ",OracleType.VarChar,10);
objcommand.Parameters[ "@username "].Value=this.TextBox1.Text;
objcommand.Parameters[ "@password "].Value=this.TextBox2.Text;
objconnection.Open();
int n=(int)objcommand.ExecuteScalar();
objconnection.Close();
if(n!=0)
{
this.Label3 .Text= "正确 ";
}
else
{
this.Label3.Text= "错误 ";
}
这段程序在SQL中可以执行.可是我是在oracle中用这段程序.运行输入用户名和密码的时候.出现错误:ORA-01036: 非法的变量名/编号
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OracleClient.OracleException: ORA-01036: 非法的变量名/编号
就是运行到这里出错了int n=(int)objcommand.ExecuteScalar();
请问在oracle里怎么用这个呀.
------解决方案--------------------oracle的参数把@ 改成:
具体你可以参考一下petshop的oracleDal层
------解决方案--------------------select count(*) from tbl_admin where username=? and password=?
Oracle中是用问号来表示的,不是像SqlServer用@var来表示的
------解决方案--------------------string query= "select count(*) from tbl_admin where username=:username and password=:password ";
objconnection=new OracleConnection(ConfigurationSettings.AppSettings[ "CnStirng "]);
OracleCommand objcommand=new OracleCommand(query,objconnection);
objcommand.Parameters.Add( ":username ",OracleType.VarChar,10);
objcommand.Parameters .Add( ":password ",OracleType.VarChar,10);
objcommand.Parameters[ ":username "].Value=this.TextBox1.Text;
objcommand.Parameters[ ":password "].Value=this.TextBox2.Text;
objconnection.Open();
int n=(int)objcommand.ExecuteScalar();
objconnection.Close();
if(n!=0)
{
this.Label3 .Text= "正确 ";
}
else
{
this.Label3.Text= "错误 ";
}