我有一個返回布爾值的存儲過程。 (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
錯誤:
Operator == cannot be applied to type bool to int"
我的存儲過程返回一個包含0或1多行,我想是因爲我想要做的就是這些值檢查它是否等於假(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;
}
}
什麼是結果集的樣子喜歡? 'Read'只會使每行中的指針前進。 –
返回一個布爾值或返回多行? –
你的問題很混亂。你想返回所有行,還是隻返回一個結果?如果它是一個結果,那麼結果代表什麼? –