我有一个返回布尔值的存储过程。(0 或 1)。它返回多行。我的问题是如何遍历所有结果。
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBReader"].ConnectionString))
{
using (SqlCommand com = new SqlCommand("Reader.usp_CheckerIsStopped", con))
{
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@fld_UserID", SqlDbType.Int).Value = this.UserID;
con.Open();
SqlDataReader dr = com.ExecuteReader();
if (dr.Read() == 1)
{
return true;
}
else
{
return false;
}
}
}
它有一个错误dr.Read() == 1
错误:
运算符 == 不能应用于类型 bool 到 int"
我的存储过程返回包含 0 或 1 的多行,我想获取这些值,因为我想检查它是否等于 true 或 false(0 或 1)
if (e.Row.RowType == DataControlRowType.DataRow)
{
//if (e.Row.Cells[11].Text == "In Progress")
//{
// System.Web.UI.WebControls.ImageButton StartImageButton = (System.Web.UI.WebControls.ImageButton)e.Row.Cells[1].FindControl("StartImageButton");
// StartImageButton.Visible = false;
//}
gvfunct.UserID = Convert.ToInt32(Session["UserID"]);
gvfunct.CheckIsStopped();
if (gvfunct.CheckIsStopped() == true)
{
System.Web.UI.WebControls.ImageButton StartImageButton = (System.Web.UI.WebControls.ImageButton)e.Row.Cells[2].FindControl("StartImageButton");
StartImageButton.Visible = true;
System.Web.UI.WebControls.ImageButton StopImageButton = (System.Web.UI.WebControls.ImageButton)e.Row.Cells[1].FindControl("StopImageButton");
StopImageButton.Visible = false;
}
else
{
System.Web.UI.WebControls.ImageButton StopImageButton = (System.Web.UI.WebControls.ImageButton)e.Row.Cells[1].FindControl("StopImageButton");
StopImageButton.Visible = true;
System.Web.UI.WebControls.ImageButton StartImageButton = (System.Web.UI.WebControls.ImageButton)e.Row.Cells[2].FindControl("StartImageButton");
StartImageButton.Visible = false;
}
}