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 */ }
aru vPosted Apr 13, 2009, 12:59 AM
Hi Harshad,
You can mail me the project to [email protected].
If the application is not responding means there might be
i) Data base connection issue.
ii)Query is taking much time to pull the data from Database.
iii)Problem with the transaction.Trying to pull data from a table which is in transaction.
Thanks,
Aru
Jan MontanoPosted Apr 12, 2009, 10:05 PM
Harshad PatelPosted Apr 9, 2009, 4:00 AM
aru vPosted Apr 9, 2009, 2:15 AM
Hi Harshad,
Can you please provide some more details about the error you are getting...
Thanks,
Aru
Harshad PatelPosted Apr 8, 2009, 5:03 AM
Thanks Jan for responding.
Aru's solution does not work. In fact the compiler hangs i.e. when I press the button "Enter" nothing happen. I am new to this form so don't know how to post the entire project.
Jan MontanoPosted Apr 8, 2009, 4:55 AM
At what exact line of the code does it throw an error?
Harshad PatelPosted Apr 8, 2009, 4:51 AM
Hi Aru,
You solution didn't work
aru vPosted Apr 8, 2009, 3:02 AM
Hi,
I'm not sure about the error u got,but try this i hope this may be the problem,
this
.oleDbDataAdapter.SelectCommand.CommandText = "SELECT * FROM Orders WHERE ProductArea = '" + this.cmbProduct.Text + "'";Let me know if it isnot the issue you have
Thanks,
Aru
Jan MontanoPosted Apr 7, 2009, 10:15 PM
I'm having a hard time reading the code because it's not properly formatted. Could you repost your code using Internet Explorer? Copy the code from Visual Studio then repost it via Internet explorer.
I also can't find "ProductArea = Hair Gel" anywhere in the code. I don't know where to look.