Skip to content

Want to launch a query that will write from C# To Access

Sarah Good

Asked Jun 1, 2016, 1:03 PM EDT1 answer
Share
LinkedInX

 I want to launch a query that will write a 3 fields on a C# winforms back to an ms-access database


 Pressing the button Add Time Sheet executes the query and returns an error Syntax error comma in query expression

 
ERRORSystem.Data.OleDb.OleDbException (0x80040E14): Syntax error (comma) in query expression '('6/4/2016', '99', 'Rami')'. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) ...
 
 

You can see the error in the linked screenshot and a part of it above.

When I try put one field in the query my query writes back to access database successfully. it only gives me the comma error when i try to insert multiple fields

 
 
 
 
Below is a Copy Past of the code in the image above.
 
 
TypeScript
 private void button1_Click(object sender, EventArgs e)

{

     try


     {
PowerShell
    connection.Close();

    connection.Open();
                            
    OleDbCommand command = new OleDbCommand();
    command.Connection = connection;
    command.CommandText = 
    "INSERT INTO ResourceWorkHours (WorkWeek, HoursWorked,FirstName) 
       SELECT ('" + ddlWeeks2.Text + "','" 
            + txtWorkHours.Text + "','" 
            + cbResourceFirstName.Text + "') 
       FROM Resources 
       INNER JOIN ResourceWorkHours 
       ON Resources.ResourceID = ResourceWorkHours.ResourceID";


      command.ExecuteNonQuery();

      MessageBox.Show("Employee Added to Database");
                           
      connection.Close();


}catch
 (Exception ex){ 
       MessageBox.Show("ERROR" + ex); } connection.Close();
      }
}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    My objective is to insert into Hoursworked table by selecting the FirstName (for example Jack) in the resources table and inserting his primary key into Hoursworked table in the foreign key table along with the hours he worked and work week.
    0