datacommand dcommand=new datacommand(); datareader dr=new datareader(); ...dcommand.commandtxt="select count(*) from user_table where username='username'"; dr.fill(datatable);if(datatable.rows>0) { //存在该用户 MessageBox.Show("该用户已注册!"); } 大致就是这样了,具体还要看你的数据是什么类型
select count(*) from user_table where username='username'
select count(*) from user_table where username='username' int res=Convert.toInt32(cmd.ExecuteScalar ()); if(res>0) // 存在 else //不存在
string sql = "select count(*) from [user] where username = '"+username.Text+"'"; int count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.Conn, CommandType.Text, sql)); if (count > 0) flag = true;'存在 else flag = false;'不存在 using (SqlConnection conn = new SqlConnection("")) { conn.Open(); SqlCommand Comm = new SqlCommand("", conn); SqlDataReader reader = Comm.ExecuteReader(CommandBehavior.CloseConnection ); if(reader.Read()) {
} }
string yxname = this.TByxname.Text.ToString(); string connectionString = WebConfigurationManager.ConnectionStrings["Pubs"].ConnectionString; SqlConnection conn1 = new SqlConnection(connectionString);//定义SQL连接 SqlCommand cmd1 = new SqlCommand("Select count(*) from yuanxiao where zh='" + yxname + "'", conn1); SqlDataAdapter sda = new SqlDataAdapter(cmd1); DataTable dt = new DataTable(); sda.Fill(dt); if (dt.Rows.Count > 0) { //存在该用户 Response.Write("<script language='javascript'>alert('用户名存在!') </script>"); } else {.....为什么一直提示我“用户名存在” ??
datareader dr=new datareader();
...dcommand.commandtxt="select count(*) from user_table where username='username'";
dr.fill(datatable);if(datatable.rows>0)
{
//存在该用户
MessageBox.Show("该用户已注册!");
}
大致就是这样了,具体还要看你的数据是什么类型
int res=Convert.toInt32(cmd.ExecuteScalar ());
if(res>0)
// 存在
else
//不存在
int count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.Conn, CommandType.Text, sql));
if (count > 0)
flag = true;'存在
else
flag = false;'不存在 using (SqlConnection conn = new SqlConnection(""))
{
conn.Open();
SqlCommand Comm = new SqlCommand("", conn);
SqlDataReader reader = Comm.ExecuteReader(CommandBehavior.CloseConnection );
if(reader.Read())
{
}
}
string connectionString = WebConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;
SqlConnection conn1 = new SqlConnection(connectionString);//定义SQL连接
SqlCommand cmd1 = new SqlCommand("Select count(*) from yuanxiao where zh='" + yxname + "'", conn1);
SqlDataAdapter sda = new SqlDataAdapter(cmd1);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
//存在该用户
Response.Write("<script language='javascript'>alert('用户名存在!') </script>");
}
else
{.....为什么一直提示我“用户名存在”
??