dr.GetString(dr.GetOrdinal(""))问题
[code=C#][/code]
private void frmmain_Load(object sender, EventArgs e)
{
string logintime;
string connstring = "Data Source=PC-20120129PSKS\\SQLEXPRESS;Initial Catalog=studens;Integrated Security=True";
SqlConnection conn1 = new SqlConnection(connstring);
conn1.Open();
logintime=DateTime.Now.ToLongTimeString();
SqlCommand cmd = new SqlCommand("select Username ," + "Types from stu_user" ,conn1);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
label8.Text = dr.GetString(dr.GetOrdinal("Username"));
if (dr.GetString(dr.GetOrdinal("Types")) == "超级用户")
{
button1.Enabled = false;
button4.Enabled = false;
}
}
怎么IF语句判断不了啊,已经证明dr.GetString(dr.GetOrdinal("Types"))中读出数据了。
------解决方案--------------------
dr.GetString(dr.GetOrdinal("Types")).Trim()