dbhlpe.conn.Open();
string sql = "select * from userId where famName=@5";
SqlCommand cmd = new SqlCommand(sql, dbhlpe.conn);
cmd.Parameters.Add("@5", SqlDbType.VarChar).Value = textBox1.Text;
int count = (int)cmd.ExecuteScalar();
if (count > 0)
{
MessageBox.Show("帐户已存在,请重新选取帐号");
textBox1.Text = "";
textBox1.Focus();
button1.Enabled = false;
}
else
{
MessageBox.Show("当前帐户可用");
button1.Enabled = true;
}
输入已经存在的数据,还是弹出对话框来说帐户已经存在,但是输入没有存在的数据就报错
int count = (int)cmd.ExecuteScalar();
未将对象引用设置到对象的实例。请帮忙看看
string sql = "select * from userId where famName=@5";
SqlCommand cmd = new SqlCommand(sql, dbhlpe.conn);
cmd.Parameters.Add("@5", SqlDbType.VarChar).Value = textBox1.Text;
int count = (int)cmd.ExecuteScalar();
if (count > 0)
{
MessageBox.Show("帐户已存在,请重新选取帐号");
textBox1.Text = "";
textBox1.Focus();
button1.Enabled = false;
}
else
{
MessageBox.Show("当前帐户可用");
button1.Enabled = true;
}
输入已经存在的数据,还是弹出对话框来说帐户已经存在,但是输入没有存在的数据就报错
int count = (int)cmd.ExecuteScalar();
未将对象引用设置到对象的实例。请帮忙看看
判断 结果是0 还是1
string sql = "select count(*) from userId where famName=@5";
SqlCommand cmd = new SqlCommand(sql, dbhlpe.conn);
cmd.Parameters.Add("@5", SqlDbType.VarChar).Value = textBox1.Text;
int count = (int)cmd.ExecuteScalar();
if (count > 0)
{
MessageBox.Show("帐户已存在,请重新选取帐号");
textBox1.Text = "";
textBox1.Focus();
button1.Enabled = false;
}
else
{
MessageBox.Show("当前帐户可用");
button1.Enabled = true;
}