我的存储过程:
CREATE procedure Login @username varchar(20),@password varchar(20),@result varchar(20) OUTPUT as
begin
if exists(select * from UserInfo where userName=@username and userPass=@password)
set @result='good'
else
set @result='bad'
end
GO调用存储过程的方法:
public string getValue(ArrayList ParamList, string ProcedureName)
{
getOpen();
SqlCommand myCmd = new SqlCommand();
myCmd.Connection = myCon;
myCmd.CommandText = ProcedureName;
myCmd.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < ParamList.Count; i++)
{
myCmd.Parameters.Add(ParamList[i].ToString());
}
myCmd.Parameters.Add("@result", SqlDbType.VarChar, 20);
myCmd.Parameters["@result"].Direction = ParameterDirection.Output;
myCmd.ExecuteNonQuery();
string result = myCmd.Parameters["@result"].Value.ToString();
myCmd.Dispose();
return result;
}
添加参数列表
protected void Button1_Click(object sender, EventArgs e)
{
ArrayList myList = new ArrayList();
myList.Add("xiaolin");
myList.Add("123456");
string result = mySql.getValue(myList, "Login");
if (result == "good")
Response.Redirect("Index.aspx");
else
{
test2.InnerHtml = "用户名或密码错误";
}
}
运行时myCmd.Parameters.Add(ParamList[i].ToString())出现错误 ,提示 SqlParameterCollection 只接受非空的 SqlParameter 类型对象,不接受 String 对象请问是为什么
CREATE procedure Login @username varchar(20),@password varchar(20),@result varchar(20) OUTPUT as
begin
if exists(select * from UserInfo where userName=@username and userPass=@password)
set @result='good'
else
set @result='bad'
end
GO调用存储过程的方法:
public string getValue(ArrayList ParamList, string ProcedureName)
{
getOpen();
SqlCommand myCmd = new SqlCommand();
myCmd.Connection = myCon;
myCmd.CommandText = ProcedureName;
myCmd.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < ParamList.Count; i++)
{
myCmd.Parameters.Add(ParamList[i].ToString());
}
myCmd.Parameters.Add("@result", SqlDbType.VarChar, 20);
myCmd.Parameters["@result"].Direction = ParameterDirection.Output;
myCmd.ExecuteNonQuery();
string result = myCmd.Parameters["@result"].Value.ToString();
myCmd.Dispose();
return result;
}
添加参数列表
protected void Button1_Click(object sender, EventArgs e)
{
ArrayList myList = new ArrayList();
myList.Add("xiaolin");
myList.Add("123456");
string result = mySql.getValue(myList, "Login");
if (result == "good")
Response.Redirect("Index.aspx");
else
{
test2.InnerHtml = "用户名或密码错误";
}
}
运行时myCmd.Parameters.Add(ParamList[i].ToString())出现错误 ,提示 SqlParameterCollection 只接受非空的 SqlParameter 类型对象,不接受 String 对象请问是为什么
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货