public string Proc_test(int student_id, int class_id)
{
string str_conn= string.Format("Data Source=DADI-PC\\MYSQL2008;Initial Catalog=Test;Persist Security Info=True;User ID=sa;Password=mysql2008");
using (SqlConnection conn = new SqlConnection(str_conn))
{
conn.Open();
SqlParameter par1 = new SqlParameter("@stu_id", SqlDbType.Int);
par1.Value = student_id;
SqlParameter par2 = new SqlParameter("@class_id", SqlDbType.Int);
par2.Value = class_id;
SqlParameter par3 = new SqlParameter("@nun", SqlDbType.VarChar, 50);
par3.Direction = ParameterDirection.ReturnValue;
SqlCommand cmd = new SqlCommand("proc_test", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(par1);
cmd.Parameters.Add(par2);
cmd.Parameters.Add(par3);
cmd.ExecuteNonQuery();
return cmd.Parameters["@nun"].Value.ToString();
}
}
ALTER proc [dbo].[proc_test]
@stu_id int,
@class_id int,
@nun varchar(50) output
as
begin
if exists( select student_str_id from Student where Student_id=@stu_id and Class_id=@class_id)
select @nun='true';
else
select @nun='flase';
end
你好歹把什么错给贴出来呀
par3.Direction = ParameterDirection.ReturnValue;
这句,你用的是output参数 这里枚举用错了