c#统计表中元素个数
zhimu 2006-12-21 09:07:00 统计user表中元素个数,用来判断用户名是否存在:
if语句中的判断条件应该怎么设置?请指点一下!
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string sql = "select count(*) from [user] where [uname]='"+TextBox1.Text.Trim()+"'";
SqlDataAdapter da = new SqlDataAdapter(sql,conn);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Columns.Count > 0)
{
Label5.Text = "该用户名已经存在";
Label5.Visible = true;
}
if(ds.Tables[0].Columns.Count == 0)
{
Label5.Visible = false;
if (TextBox2.Text.Trim() == TextBox3.Text.Trim())
{
Response.Redirect("ok.aspx");
}
else
{
Label6.Text = "前后密码不一致";
Label6.Visible = true;
}
}
conn.Close();