I get this error - Syntax error (missing operator) in query expression 'ProductArea = Hair Gel' This is my code -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Salon_Order_A
{
public partial class SummaryofOrders : Form
private int Hair; private OleDbCommand oleDbSelectCommand;
/*==============================================*/
/* MS Access connection string using Jet 4.0: */
public static string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source = " + Application.StartupPath + "\\SalonOrderDb.mdb";
/* Define ADO .NET Objects */
private OleDbDataAdapter dataAdapter;
private DataSet dataSet;
private DataTable dataTable;
private OleDbConnection conn;
/* Define Database Objects */
private static string OrderNo;
private static string ProductArea;
private static string Consultant;
private static string Total;
public SummaryofOrders()
InitializeComponent();
/* Default select command on the OrderNobers table */
string commandstring = "select * from Orders";
/* The link between the sql command and the database connection */
dataAdapter = new OleDbDataAdapter(commandstring, connectionString);
/* Define insert, update, and delete sql commands to use. */
BuildCommands();
/* Declare and fill the in-memory dataset from the database */
dataSet = new DataSet();
dataSet.CaseSensitive = true;
dataAdapter.Fill(dataSet,"Orders");
/* Show all rows in the listbox */
Fill_lb();
}
/* End of SummaryOrders Method */
/* Method - Show all rows in the OrderNobers table in the listbox */
private void Fill_lb()
dataTable = dataSet.Tables[0];
listBox.Items.Clear();
foreach (DataRow dataRow in dataTable.Rows)
LoadBuffers(dataRow); listBox.Items.Add(OrderNo + "\t\t" + ProductArea + "\t\t" + Consultant + "\t\t" + Total);
/* Method - Load global strings from column values in the datarow */
private void LoadBuffers(DataRow prow)
OrderNo = prow["OrderNo"].ToString().Trim();
ProductArea = prow["ProductArea"].ToString().Trim();
Consultant = prow["Consultant"].ToString().Trim();
Total = prow["Total"].ToString().Trim();
private void BuildCommands()
OleDbConnection connection = (OleDbConnection)dataAdapter.SelectCommand.Connection;
/* Use the select command's connection again */
/* Declare a reusable insert command with parameters */
dataAdapter.InsertCommand = connection.CreateCommand();
dataAdapter.InsertCommand.CommandText = "insert into Orders " + "(OrderNo, ProductArea, Consultant, Total) " + "values " + "(?, ?, ?, ?)";
dataAdapter.InsertCommand.Parameters.Add("OrderNo", OleDbType.Char, 0, "OrderNo");
dataAdapter.InsertCommand.Parameters.Add("ProductArea", OleDbType.Char, 0, "ProductArea");
dataAdapter.InsertCommand.Parameters.Add("Consultant", OleDbType.Char, 0, "Consultant");
dataAdapter.InsertCommand.Parameters.Add("Total", OleDbType.Char, 0, "Total");
#region
/* Declare a reusable update command with parameters (required if update in databse is */
/* is required) */
/* dataAdapter.UpdateCommand = connection.CreateCommand(); */
/* dataAdapter.UpdateCommand.CommandText = "update Orders " + "set ProductArea = ? " + */
/* "set Consultant = ? " + "set Total = ? " + "where OrderNo = ? "; */
/* dataAdapter.UpdateCommand.Parameters.Add("OrderNo", OleDbType.Char, 0, "OrderNo"); */
/* dataAdapter.UpdateCommand.Parameters.Add("ProductArea", OleDbType.Char, 0, "ProductArea"); */
/* dataAdapter.UpdateCommand.Parameters.Add("Consultant", OleDbType.Char, 0, "Consultant"); */
/* dataAdapter.UpdateCommand.Parameters.Add("Total", OleDbType.Char, 0, "Total"); */
/* Declare a reusable delete command with parameters */
/* dataAdapter.DeleteCommand = connection.CreateCommand(); */
/* dataAdapter.DeleteCommand.CommandText = */
/* "delete from OrderNobers where OrderNo = ?"; */
/* dataAdapter.DeleteCommand.Parameters.Add("OrderNo", OleDbType.Char, 0, "OrderNo"); */
#endregion
private void btnEnter1_Click_1(object sender, EventArgs e)
try
this.oleDbDataAdapter.SelectCommand.CommandText = "SELECT * FROM Orders WHERE ProductArea = " + this.cmbProduct.Text;
//"DELETE FROM BookDb WHERE ISBN =" + this.isbn_textBox.Text;
/*+ this.cmbProduct.Text;*/
// clear the DataSet from the last operation dataSet11.Clear();
this.oleDbDataAdapter.Fill(this.dataSet11.Tables["Orders"]);
catch (OleDbException exp)
MessageBox.Show(exp.ToString());
//copy the dataset in datatable object DataTable dataTable = dataSet11.Tables[0];
//if the row count = 0 then the qurey return nothing
if (dataTable.Rows.Count == 0)
MessageBox.Show("Record not found");
private void button1_Click(object sender, EventArgs e)
this.Close();
/* Class SummaryofOrders ends here */ }