I'm trying to put data into my database at the same time but in different tables, I've tried to squish the query into one line but it doesn't seem to work.
private void btnBorrows_Click(object sender, EventArgs e)
{
string connectionString = @"Provider=Microsoft Office 12.0 Access Database Engine OLE DB Provider;" + @"Data source= C:\Users\Administrator\Desktop\dtbase\Database1.accdb";
string queryString = "SELECT Availability FROM Books WHERE ID = " + txtbxBookId.Text + "";
string input1 = "insert into AuditTrail (MemberID, MemberName, BookID, BookTitle, DateBorrowed, ReturnDate, Status) values ('" + txtbxMId.Text + "', '" + txtbxMN.Text + "', '" + txtbxBookId.Text + "', '" + txtbxBookTitle.Text + "', '" + txtbxDateNow.Text + "', '" + txtbxReturn.Text + "', '" + txtbxStatus.Text + "')";
string input2 = "update Books set Availability = '" + txtbxStatus.Text + "' where ID = " + txtbxBookId.Text + " ";
try
{
OleDbConnection connection = new OleDbConnection(connectionString)
OleDbCommand command = new OleDbCommand(queryString, connection);
connection.Open();
command.Connection = connection;
command.CommandText = queryString;
command.CommandText = input1;
command.Connection = connection;
command.CommandText = queryString;
command.CommandText = input2;
command.ExecuteNonQuery();
MessageBox.Show("Borrowed!");
return;
}
catch(Exception ex)
{
}
}
I don't know how to do it at the same time, I don't know the logic. But the program just jumps into the "input2" and ignores the "input1". The program will work well if I erased one of the two.