首先是在SQLServer 2000中創建存儲過程
CREATE PROCEDURE p_Login
@UserID varchar(20), --用戶名
@PassWord varchar(20), --密碼
@Result varchar(50) OUTPUT --登錄結果
AS
begin
select @Result = Name from student where TestCardID = @UserID and password = @PassWord
--print @Result
end
GO
----------------------------------------------------------------------------
上面的存儲過程是返回Result值,以便在程序中使用! string cnnString = System.Configuration.ConfigurationSettings.APPSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(cnnString);
SqlCommand comm = new SqlCommand("p_Login",conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@UserID",SqlDbType.VarChar,50);
comm.Parameters["@UserID"].Value =userID;
comm.Parameters.Add("@PassWord",SqlDbType.VarChar,50);
comm.Parameters["@Password"].Value = passWord;
comm.Parameters.Add("@Result",SqlDbType.VarChar,50);
comm.Parameters["@Result"].Direction = ParameterDirection.Output;
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
return comm.Parameters["@Result"].Value.ToString();