Getting Syntax error while executing the INSERT INTO query

Mar 27 2009 5:30 PM
public void button2_Click_1(object sender, EventArgs e)
        {
            
            if (textBox1.Text == "")
                MessageBox.Show("Select an application to run");
            else
            {
                if (cmbhr.SelectedIndex == -1 || cmbmin.SelectedIndex == -1 || cmbtime.SelectedIndex == -1)
                    MessageBox.Show("Select proper time format HH:MM:AM/PM");
                else
                {
                    //generate the time string from the selected values of HH:MM AM/PM
                    s = cmbhr.SelectedItem.ToString() + ":" + cmbmin.SelectedItem.ToString() + " " + cmbtime.SelectedItem.ToString();

                    MessageBox.Show(s);
                    
                    //SMTimberDB() start ;// Call database function
                    try
                    {

                        
                        mycon.Open();
                        MessageBox.Show("mycon.Open();");
                        command1 = string.Format("Insert into STable(Date,Time,Program) VALUES('" + Selected_Date + "','" + s + "','" + filepath + "')");
                        MessageBox.Show("Insert into STable(Date,Time,Program");
                        cmdIns = new OleDbCommand(command1, mycon);
                        MessageBox.Show("cmdIns = new OleDbCommand(command1, mycon);");
                        //for (int xt = 0; xt < d.stl; xt++)
                        //{
                        //    string ntime = d.sds.Tables["STable"].Rows[xt]["Time"].ToString();
                        //    if (ntime == s)
                        //    {
                        //        MessageBox.Show("Time already in use !! ");
                        //        break;
                        //    }

                        //}
                        cmdIns.Connection = mycon;
                        MessageBox.Show("cmdIns.Connection = mycon;");
                        cmdIns.CommandText = command1;
                        MessageBox.Show("cmdIns.CommandText = command1;");
                        int xx = cmdIns.ExecuteNonQuery();
                        string number = xx.ToString();
                        MessageBox.Show(number);
                        if (xx > 0)
                        {
                            MessageBox.Show("Scheduler Added !! ");

                        }
                        MessageBox.Show("Add new sheduler");
                    }

                    
                    catch (InvalidOperationException)
                    {
                        MessageBox.Show("Request can not be completed due to SQL statement error");
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.Message);
                        // Message not required

                    }
                    finally
                    {
                        //mycon.Close();
                    }

                    //SMTimberDB() end

                    
                }
            }

Answers (1)