C#更新查询语法错误(快速)

时间:2017-05-23 21:55:34

标签: c# database vba visual-studio ms-access

这里非常简单,因为我对编码C#非常陌生。正如您所提供的代码所示,我试图解决错误,我在屏幕截图中显示了接收信息。当我尝试更新访问数据库中保存的当前信息时,就会发生这种情况。 正如我所说,可能只是一个,但我无法看到错误

enter image description here

private void btnSchedule_Click(object sender, EventArgs e)
    {
        try
        {

            connection.Open();
            OleDbCommand command = new OleDbCommand();
            command.Connection = connection;
            string query = "Update patients SET First = '" + txtFirst.Text 
               + "', Last='" + txtLast.Text 
               + "', Address='" + txtAddress.Text 
               + "', Phone='" + txtPhone.Text 
               + "', LastVisit='" + txtLastVisit.Text 
               + "', NextVisit='" + txtNextVisit.Text 
               + "', Doctor='" + comboDoctor.Text 
               + "' WHERE patients.ID =" + lblID.Text + " ";
            command.CommandText = query;
            command.ExecuteNonQuery();
            MessageBox.Show("User Updated");
            connection.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show("User not updated " + ex);
        }
    }

0 个答案:

没有答案