I am making a database system. I've implemented the INSERT function properly but when I tried implementing the UPDATE function, I couldn't make any changes to the database. I don;t know where I went wrong.
Note: username is declared as string
我正在做一个数据库系统。我已经正确地实现了INSERT函数,但是当我尝试实现UPDATE函数时,我无法对数据库做任何更改。我不知道哪里出错了。注意:用户名被声明为字符串
Here is the function handling the UPDATE:
下面是处理更新的函数:
private void btnUpdate_Click(object sender, EventArgs e)
{
string q = "UPDATE [registrationinfo] SET [Password]='?', [EmailAdd]='?', [HomeAdd]='?' WHERE [Username]='?'";
OleDbConnection connect = new OleDbConnection(MyConnectionString);
connect.Open();
try
{
OleDbCommand command = new OleDbCommand(q,connect);
command.Parameters.AddWithValue("@Password", txt_password.Text);
command.Parameters.AddWithValue("@EmailAdd", txt_eadd.Text);
command.Parameters.AddWithValue("@HomeAdd", txt_homeadd.Text);
command.Parameters.AddWithValue("Username", username);
command.ExecuteNonQuery();
txt_password.Clear();
txt_eadd.Clear();
txt_homeadd.Clear();
txt_conPass.Clear();
}
catch (Exception ex)
{
connect.Close();
MessageBox.Show(ex.Message.ToString());
}
connect.Close();
}
1 个解决方案
#1
3
When using a parameterized query you do not need to put single quotes ('
) around text parameters in your CommandText, so you should be using something like this:
当使用参数化查询时,您不需要在CommandText中为文本参数设置单引号,因此您应该使用以下方法:
string q = "UPDATE [registrationinfo] SET [Password]=?, [EmailAdd]=?, [HomeAdd]=? WHERE [Username]=?";
#1
3
When using a parameterized query you do not need to put single quotes ('
) around text parameters in your CommandText, so you should be using something like this:
当使用参数化查询时,您不需要在CommandText中为文本参数设置单引号,因此您应该使用以下方法:
string q = "UPDATE [registrationinfo] SET [Password]=?, [EmailAdd]=?, [HomeAdd]=? WHERE [Username]=?";