数据库获取的值比较
string st = "Data Source=.;Initial Catalog=master;User ID=sa;password=123;";
SqlConnection sjconn = new SqlConnection(st);
//string sql = "Select * from Table1 where id='" + id + "'";
string sql = "Select * from Table1 where yname='admin'";
SqlCommand comm = new SqlCommand(sql, sjconn);
sjconn.Open();
SqlDataReader dr = comm.ExecuteReader();
if (dr.Read())
{
if (dr["zeng"].ToString() == "否")
{
Response.Write("123");
}
}
这样比较有问题吗? 着急啊?问题就是不能比较啊
------解决方案--------------------
类型对不?
if (dr["zeng"].ToString().Trim() == "否")
------解决方案--------------------
string st = "Data Source=.;Initial Catalog=master;User ID=sa;password=123;";
SqlConnection sjconn = new SqlConnection(st);
string sql = "Select * from Table1 where yname='admin'";
SqlCommand comm = new SqlCommand(sql, sjconn);
sjconn.Open();
SqlDataReader dr = comm.ExecuteReader();
if(dr.Read())
{
if (dr["zeng"].ToString().Trim() == "否")
{
Response.Write("123");
}
}