CREATE PROCEDURE ValidationLogin
@LogInName char(50)=NULL,
@Password char(50)=NULL,
@blnError char(255) output
--WITH ENCRYPTION
ASBEGIN
IF exists (select * from [User] where LogInName=(@LogInName))
BEGIN
IF exists (select * from [User] where LogInName=(@LogInName) and Password=(@Password))
BEGIN
set @blnError = '用户登录成功!'
END
ELSE
BEGIN
set @blnError = '用户密码错误!'
END
END
ELSE
BEGIN
set @blnError = '用户名不存在!'
END
ENDGO
string connstr = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connstr);
SqlCommand myCommand = new SqlCommand("ValidationLogin", myConnection); //存储过程名称
myCommand.CommandType = CommandType.StoredProcedure; //设置调用的类型为存储过程 myCommand.Parameters.Add("@LogInName", SqlDbType.VarChar,50).Value = txtName.Text.Trim();
myCommand.Parameters.Add("@Password", SqlDbType.VarChar,50).Value = txtPassword.Text.Trim();
myCommand.Parameters.Add("@blnError", SqlDbType.VarChar).Direction = ParameterDirection.Output; myCommand.Connection.Open();
//SqlDataReader MyRst = myCommand.ExecuteReader();
myCommand.ExecuteNonQuery();
//myConnection.Close();
//string strMsg = myCommand.Parameters["@blnError"].Value.ToString();
MessageBox("strMsg", "Login.aspx");说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: String[2]: Size 属性具有无效大小值 0。源错误:
行 41: myCommand.Connection.Open();
行 42: //SqlDataReader MyRst = myCommand.ExecuteReader();
行 43: myCommand.ExecuteNonQuery();
行 44: //myConnection.Close();
行 45: //string strMsg = myCommand.Parameters["@blnError"].Value.ToString();
@LogInName char(50)=NULL,
@Password char(50)=NULL,
@blnError char(255) output
--WITH ENCRYPTION
ASBEGIN
IF exists (select * from [User] where LogInName=(@LogInName))
BEGIN
IF exists (select * from [User] where LogInName=(@LogInName) and Password=(@Password))
BEGIN
set @blnError = '用户登录成功!'
END
ELSE
BEGIN
set @blnError = '用户密码错误!'
END
END
ELSE
BEGIN
set @blnError = '用户名不存在!'
END
ENDGO
string connstr = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connstr);
SqlCommand myCommand = new SqlCommand("ValidationLogin", myConnection); //存储过程名称
myCommand.CommandType = CommandType.StoredProcedure; //设置调用的类型为存储过程 myCommand.Parameters.Add("@LogInName", SqlDbType.VarChar,50).Value = txtName.Text.Trim();
myCommand.Parameters.Add("@Password", SqlDbType.VarChar,50).Value = txtPassword.Text.Trim();
myCommand.Parameters.Add("@blnError", SqlDbType.VarChar).Direction = ParameterDirection.Output; myCommand.Connection.Open();
//SqlDataReader MyRst = myCommand.ExecuteReader();
myCommand.ExecuteNonQuery();
//myConnection.Close();
//string strMsg = myCommand.Parameters["@blnError"].Value.ToString();
MessageBox("strMsg", "Login.aspx");说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: String[2]: Size 属性具有无效大小值 0。源错误:
行 41: myCommand.Connection.Open();
行 42: //SqlDataReader MyRst = myCommand.ExecuteReader();
行 43: myCommand.ExecuteNonQuery();
行 44: //myConnection.Close();
行 45: //string strMsg = myCommand.Parameters["@blnError"].Value.ToString();
解决方案 »
- 怎么理解MSMQ的事务
- 300分分享:两行代码取得当前网站的(无交互状态下的)网页html源代码就够了,不用对asp.net网页设计技术进行一点点倒退
- 有没有什么办法能够捕获向服务器请求JS文件的事件?
- 关于内网使用ASP.NET(设置了代理服务器)
- 请高手指点!不能新建项目?
- 如何去掉DataGrid中的"0"值显示?
- datagrid 动态绑定列问题!!!!
- 如何连接Sybase数据库?
- 怎样在Asp.net的页面中显示word,execl的内容?
- 最后的46分,散了,走人了。以后不想来CSDN...这里的人太菜了。
- 问个正则,急用
- 求助:关于GridView的行选中问题..就是行选中事件,高手帮忙啊!
而varchar类型是可变长的另外:
异常详细信息: System.InvalidOperationException: String[2]: Size 属性具有无效大小值 0。
根据这个提示改为试试:
myCommand.Parameters.Add("@blnError", SqlDbType.VarChar,255).Direction = ParameterDirection.Output;