0
对不起,我的英语不好。检查并显示数据库中的标签
这是我的问题。我可以在tb_acc
中键入不同的用户名,并在Label1
中显示现有用户的全名,但对于不存在的用户,它不显示字符串User not found.
是DBNull.Value
在此不适用吗?我有AutoPostBack
的文本框设置为true
。
if (IsPostBack)
{
try
{
using (OleDbCommand com = new OleDbCommand("select childName from family where childID='" + tb_acc.Text + "'", con))
{
con.Open();
OleDbDataReader myReader2 = null;
myReader2 = com.ExecuteReader();
while (myReader2.Read())
{
if (myReader2["childName"] != DBNull.Value)
{
Label1.Text = (myReader2["childName"].ToString()); //user full Name
}
else
{
Label1.Text = "User not found.";
}
}
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.ToString());
}
finally
{
con.Close();
}
}
谢谢先生!真是愚蠢的错误,对不起,我是新来的C#! –