且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将参数传递给C#中的存储过程

更新时间:2023-02-12 17:27:36

您可以尝试以下代码:

bool result=false;
SqlCommand scCommand = new SqlCommand("usp_CheckEmailMobile", sqlCon);
scCommand.CommandType = CommandType.StoredProcedure;
scCommand.Parameters.Add("@Name", SqlDbType.VarChar, 50).Value = txtName.Text;
scCommand.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = txtEmailAddress.Text;
scCommand.Parameters.Add("@Password ", SqlDbType.NVarChar, 50).Value = txtPassword.Text;
scCommand.Parameters.Add("@CountryCode", SqlDbType.VarChar.50).Value =ddlCountryCode.SelectedText;
scCommand.Parameters.Add("@Mobile", SqlDbType.NVarChar, 50).Value = txtMobileNumber.Text;
scCommand.Parameters.Add("@Result ", SqlDbType.Bit).Direction = ParameterDirection.Output;
try
{
    if (scCommand.Connection.State == ConnectionState.Closed)
    {
        scCommand.Connection.Open();
    }
    scCommand.ExecuteNonQuery();
    result = Convert.ToBoolean(scCommand.Parameters["@Result"].Value);


}
catch (Exception)
{

}
finally
{                
    scCommand.Connection.Close();
    Response.Write(result); 
}