private void button1_Click(object sender, EventArgs e) { string CS = ConfigurationManager.ConnectionStrings["connection_string"].ConnectionString; OleDbConnection C = new OleDbConnection(CS); C.Open(); OleDbCommand CMD = new OleDbCommand("", C); CMD.CommandText = "SELECT COUNT(*) FROM Applicants WHERE ApplicantID = ?"; CMD.Parameters.AddWithValue("@ApplicantID", textBox1.Text); if (Convert.ToInt32(CMD.ExecuteScalar()) > 0) { CMD.CommandText = "UPDATE Onboarding SET " + "BackgroudCheck = @BGC, PhotoID = @PID, " + "TrainingHoursOutOf40 = @THOO, DrugTestTaken = @DTT, PassedDrugTest = @PDT" + "WHERE ApplicantID = @AID"; CMD.Parameters.AddWithValue("@AID", textBox1.Text); CMD.Parameters.AddWithValue("@BGC", CheckBox1); CMD.Parameters.AddWithValue("@PID", CheckBox2); CMD.Parameters.AddWithValue("@THOO", TextBox2.Text); CMD.Parameters.AddWithValue("@DTT", CheckBox3); CMD.Parameters.AddWithValue("@PDT", CheckBox4); MessageBox.Show("Applicant Updated Successfully"); } else { MessageBox.Show("Applicant Does Not Exists"); } C.Close(); }
I am trying to update the data table. Some how when I try to update in the form I do get a messagebox saying "Applicant updated Successfully", but when I go to the data table or view it in another form, the table is not updated.
https://stackoverflow.com/questions/67328482/update-sql-data-table-in-c April 30, 2021 at 01:08PM
没有评论:
发表评论