I tried to do begin transaction on SQL Server, but it returns an error that I can't figure out what the real problem is. So here is some of my code I tried.
This is the error:
Code:
SqlConnection connection = new SqlConnection("Data Source=LOCALHOST\\SQLEXPRESS;Initial Catalog=tempdb;Integrated Security=SSPI;User ID = xxxx; Password=xxx;");
DateTime dt = dateTimePicker1.Value.Date;
dt = dt.AddDays(60);
string selectQuery = "BEGIN TRANSACTION UPDATE tester SET
test_ad=@dateTimePicker1, test_ud=@dt, test_pd=@dt WHERE
test_name=@textBox1;INSERT INTO records(testr_status, testr_name, testr_ad,
testr_ud, testr_pd, apte_name)VALUES(@testr_status, testr_name = @comboBox1,
testr_ad = @dateTimePicker1, testr_ud = @dt, testr_pd = @dt COMMIT";
connection.Open();
SqlCommand command = new SqlCommand(selectQuery, connection);
command.Parameters.AddWithValue("@dateTimePicker1",this.dateTimePicker1.Value.Date);
command.Parameters.AddWithValue("@textBox1", this.textBox1.Text);
command.Parameters.AddWithValue("@comboBox1",this.comboBox1.SelectedItem);
command.Parameters.AddWithValue("@testr_status",SqlDbType.VarChar);
command.Parameters.AddWithValue("@dt", dt);
int iResult = command.ExecuteNonQuery();
if (iResult > 0)
MessageBox.Show("Successfully saved ", "Error",MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Record not saved ", "Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
command.ExecuteNonQuery();
connection.Dispose();
command.Dispose();