从数据库中检索数据并在asp.net中比较检索到的结果c#

时间:2013-11-20 16:09:06

标签: c# asp.net sql-server

string strCon = ConfigurationManager.ConnectionStrings["conCTSystem"].ConnectionString;
SqlConnection conSchedule = new SqlConnection(strCon);

conSchedule.Open();

SqlCommand cmdSchedule = new SqlCommand("Select Day From Schedule Where RoomNumber=@roomNumber", conSchedule);
cmdSchedule.Parameters.AddWithValue("@roomNumber", ddlRoomNumber.SelectedValue); //MatchWithDropDownList

using (SqlDataAdapter da = new SqlDataAdapter(cmdSchedule))
{
    DataSet ds = new DataSet();
    da.Fill(ds);

    if (ds.Tables.Count > 0)
    {
       string ReturnDay = ds.Tables[0].Rows[0]["Day"].ToString();

       if (ReturnDay == "Monday")
       {
          Label1.Text = "abc";
       }
       else
       {
          Label1.Text = "cde";
       }
    }
 }   

任何人都可以帮我解决这个问题吗?我是使用asp.net c#的新学习者,我面临的问题是当ReturnDay等于Monday并且应该显示“abc”结果但输出显示给我的是“cde” ”

1 个答案:

答案 0 :(得分:1)

试试这个:

if (ReturnDay.Trim().Equals("Monday"))
{
    Label1.Text = "abc";
}

if (ReturnDay.Trim().Equals("Monday",StringComparison.InvariantCultureIgnoreCase))
{
    Label1.Text = "abc";
}