当我想尝试检查数据库中是否有可用性用户名时出现此错误,错误显示:“输入字符串格式不正确”。
这是代码:
private void CheckUsername()
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\Archives\Projects\Program\Sell System\Sell System\App_Data\db1.accdb";
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT [Username] FROM [Member], conn);
cmd.Parameters.Add("Username", System.Data.OleDb.OleDbType.VarChar);
cmd.Parameters["Username"].Value = this.textBox1.Text;
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count != 0)
{
System.Media.SoundPlayer sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Notify.wav");
sound.Play();
MessageBox.Show("Username already exists! Please use another username", "Warning");
}
else
{
System.Media.SoundPlayer sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Notify.wav");
sound.Play();
MessageBox.Show("Username is not exists!", "Congratulations");
}
}
错误指出:int count = Convert.ToInt32(cmd.ExecuteScalar());
并且错误说:“输入字符串的格式不正确”
提前致谢!