Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to check if a value in a label is already in the database. Is it possible?


                    OleDbDataAdapter da = new OleDbDataAdapter("Select * from [Customer Orders] Where [Order ID] = '" + PrdtID.Text + "'", MAcon);
                    DataTable dtbl = new DataTable();
                    da.Fill(dtbl);

                    if (dtbl.Rows.Count == 1)
                    {
.......
}


Each time i get the error message of
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: Syntax error (missing operator) in query expression '[Order ID] = @[Order ID]'.


What I have tried:

OleDbDataAdapter da = new OleDbDataAdapter("Select * from [Customer Orders] Where [Order ID] = @[Order ID]", MAcon);
DataTable dtbl = new DataTable();
da.Fill(dtbl);
Posted
Updated 11-Apr-18 11:12am
v2

1 solution

The code you have in the latter code block seems like a good start. what you're missing is creating and setting the value of a parameter. In other words something like

C#
OleDbDataAdapter da = new OleDbDataAdapter("Select * from [Customer Orders] Where [Order ID] = @OrderID", MAcon);
da.SelectCommand.Parameters.AddWithValue("@OrderID", PrdtID.Text);
DataTable dtbl = new DataTable();
da.Fill(dtbl);
 
Share this answer
 
v2
Comments
Maciej Los 12-Apr-18 2:22am    
Hawk eye!
Wendelius 12-Apr-18 22:52pm    
Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900