我的程序中有一个名为result
的输出值,我想在asp.net中创建if条件,检查是否result = 1
并打印语句
public partial class ManagerViewTasks : System.Web.UI.Page
{
SqlConnection sqlcon = new SqlConnection( @"data source= DODO\SQLEXPRESS; " +
"Initial Catalog = Company_103; Integrated Security = True");
protected void Button1_Click(object sender, EventArgs e)
{
if (sqlcon.State == System.Data.ConnectionState.Closed)
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand("MG_Reviews_Task",sqlcon);
sqlcmd.CommandType = System.Data.CommandType.StoredProcedure;
sqlcmd.Parameters.Add("@result ", SqlDbType.Int).Direction=ParameterDirection.Output;
sqlcmd.Parameters.AddWithValue("@re ", Txtname.Text.Trim());
sqlcmd.Parameters.AddWithValue("@task", TextBox2.Text.Trim());
sqlcmd.Parameters.AddWithValue("@proj",TextBox3.Text.Trim());
sqlcmd.Parameters.AddWithValue("@company",TextBox4.Text.Trim());
sqlcmd.Parameters.AddWithValue("@manager",TextBox5.Text.Trim());
sqlcmd.Parameters.AddWithValue("@res",TextBox6.Text.Trim());
sqlcmd.Parameters.AddWithValue("@deadline ",TextBox7.Text.Trim());
sqlcmd.ExecuteNonQuery();
sqlcon.Close();
}
}
答案 0 :(得分:0)
SqlParameter result = New SqlParameter();
result.ParameterName = "result";
result.Value = 0;
result.Size = 1;
result.Direction = ParameterDirection.Output;
sqlcmd.Parameters.Add(result);
sqlcmd.ExecuteNonQuery();
sqlcon.Close();
//Check result value here
if (result.value == 1){
//Do something;
}