c#中的登录过程,输入用户名和密码后点击登录按钮利用存储过程来判断是否合法用户。
编译正常,按F5运行后输入用户和密码后点击登录后出现如下错误:未处理的System.Data.SqlClient.SqlException类型的异常出现在system.data.dll
其它信息System error.存储过程如下:CREATE Procedure Get_loginname
(
@login_name nvarchar(20),
@login_password nvarchar(20),
@return_number int OUTPUT,
@dep_id int output,
@permit_id int output,
@description nvarchar(60) output
)
AS
select login_name from employees where login_name=@login_name
if (@@Rowcount<1)
begin
set @return_number=0
set @description='Sorry,Wrong Login Name,Please Try Again.'
end
else
begin
SELECT login_name,login_password,dep_id,permit_id
FROM employees
where login_name =@login_name and login_password=@login_password
IF (@@Rowcount < 1)
BEGIN
SET @return_number = 0
set @description='Sorry,Wrong Password,Please Try Again.'
END
else
BEGIN
SET @return_number = 1
set @description='Access.'
END
endreturn
GOLOGIN.CS中相关代码如下:private void btn_login_Click(object sender, System.EventArgs e)
{
getconnected();
this.DialogResult=DialogResult.OK;
this.Close();
} public void getconnected()
{
int dep_id;
string str_conn="server=localhost;database=hrmis;uid=sa;pwd=;";
SqlConnection myConnection=new SqlConnection(str_conn);
myConnection.Open();
SqlCommand mycommand=new SqlCommand("Get_loginname",myConnection);
mycommand.CommandType=CommandType.StoredProcedure;
mycommand.Parameters.Add(new SqlParameter("@login_name",SqlDbType.NVarChar));
mycommand.Parameters.Add(new SqlParameter("@login_password",SqlDbType.NVarChar));
mycommand.Parameters.Add(new SqlParameter("@dep_id",SqlDbType.Int,4,ParameterDirection.Output,false,0,0,"dep_id",DataRowVersion.Default,null)); mycommand.Parameters["@login_name"].Value = txt_password.Text.ToString();
mycommand.Parameters["@login_pasword"].Value = txt_password.Text.ToString();
mycommand.ExecuteNonQuery();
dep_id=(int)mycommand.Parameters["@dep_id"].Value;
myConnection.Close();
}
编译正常,按F5运行后输入用户和密码后点击登录后出现如下错误:未处理的System.Data.SqlClient.SqlException类型的异常出现在system.data.dll
其它信息System error.存储过程如下:CREATE Procedure Get_loginname
(
@login_name nvarchar(20),
@login_password nvarchar(20),
@return_number int OUTPUT,
@dep_id int output,
@permit_id int output,
@description nvarchar(60) output
)
AS
select login_name from employees where login_name=@login_name
if (@@Rowcount<1)
begin
set @return_number=0
set @description='Sorry,Wrong Login Name,Please Try Again.'
end
else
begin
SELECT login_name,login_password,dep_id,permit_id
FROM employees
where login_name =@login_name and login_password=@login_password
IF (@@Rowcount < 1)
BEGIN
SET @return_number = 0
set @description='Sorry,Wrong Password,Please Try Again.'
END
else
BEGIN
SET @return_number = 1
set @description='Access.'
END
endreturn
GOLOGIN.CS中相关代码如下:private void btn_login_Click(object sender, System.EventArgs e)
{
getconnected();
this.DialogResult=DialogResult.OK;
this.Close();
} public void getconnected()
{
int dep_id;
string str_conn="server=localhost;database=hrmis;uid=sa;pwd=;";
SqlConnection myConnection=new SqlConnection(str_conn);
myConnection.Open();
SqlCommand mycommand=new SqlCommand("Get_loginname",myConnection);
mycommand.CommandType=CommandType.StoredProcedure;
mycommand.Parameters.Add(new SqlParameter("@login_name",SqlDbType.NVarChar));
mycommand.Parameters.Add(new SqlParameter("@login_password",SqlDbType.NVarChar));
mycommand.Parameters.Add(new SqlParameter("@dep_id",SqlDbType.Int,4,ParameterDirection.Output,false,0,0,"dep_id",DataRowVersion.Default,null)); mycommand.Parameters["@login_name"].Value = txt_password.Text.ToString();
mycommand.Parameters["@login_pasword"].Value = txt_password.Text.ToString();
mycommand.ExecuteNonQuery();
dep_id=(int)mycommand.Parameters["@dep_id"].Value;
myConnection.Close();
}
解决方案 »
- c# 远程连接oracle
- C#调用delhpi的dll
- [50]如何点击关闭windowsform的时候确认是否关闭,弱是才关闭?
- 用datagrid自定义排序时 怎么改变列头的文字呀? 先谢谢了 (都第二帖了 还没有适合的答案)
- C#怎样写定时关机代码呢?调用WindowsAPI?
- 有关安装程序得制作问题啊--Checkbox的值是什么啊
- 问一个比较简单的问题[XmlAttribute("pattern")] ,这两个[]是起什么作用的?
- AxMsFlexGrid这个控件在什么地方?为什么我机子的com组件里找不到!
- 安装AD以后,以前能够运行的Web程序全部都不能用了。请问可能是哪里出现错误。
- 关于C#类的问题
- DataGrid更新时取不到页面上TextBox的值,如何解决?
- 为什么在.net里没办法掉用VC编的控件?
应该是这句出错了.
@permit_id int output,这两个是输出参数,没有看到你的存储过程中出现给这两个参数赋值的语句啊??