运行对数据库进行存取的时候,注册用户出现以下问题,单独运行第一段用户不存在时,可以实现,想要注册新用户就出现问题,属实是不知道报错部分该怎么改了
``` MySqlConnection conn = null;
try
{
conn = new MySqlConnection(sign);
conn.Open();
string checkNameSql = "select * from userinfo where name='{0}'";
checkNameSql = string.Format(checkNameSql, textBox1.Text);
MySqlCommand cmdCheckName = new MySqlCommand(checkNameSql, conn);
int isRepeatName = (int)cmdCheckName.ExecuteScalar();//用于查询数据时,返回查询结果//会报错
if (isRepeatName != 0)
{
MessageBox.Show("用户名已存在!");
return;
}
string signnew = "insert into userinfo(name,password) values('{0}','{1}')";
signnew = string.Format(signnew, textBox1.Text, textBox2.Text);
MySqlCommand cmd = new MySqlCommand(signnew, conn);
int returnvalue = cmd.ExecuteNonQuery();//用于插入、更新、和删除数组
if (returnvalue != -1)
{
MessageBox.Show("注册成功!");
}
}