Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!


I'm getting an error at da.Fill(dt) when i run the application, it says "Incorrect syntax near '='." and it's because WHERE clause because when i comment it out it runs with no errors.
can anyone please help me?

here's some code:
C#
private void Kombi_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'kombiDBDataSet.KombiStateTbl' table. You can move, or remove it, as needed.
            this.kombiStateTblTableAdapter.Fill(this.kombiDBDataSet.KombiStateTbl);
            numberPlateComboBox.Text = oldIndexText;
            oldIndexText = numberPlateComboBox.Text;  
   

            conn.ConnectionString =(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Projects\RentalPlus\RentalPlus\KombiDB.mdf;Integrated Security=True;User Instance=True");
            conn.Open();

            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            ds.Tables.Add(dt);
            SqlDataAdapter da = new SqlDataAdapter();
            String Param1 = this.Text;

            da = new SqlDataAdapter("SELECT RentalTbl.NumberPlate, RentalTbl.PricePD, RentalTbl.FromDate,"
            + "RentalTbl.ToDate, ClientTbl.CompanyName, ClientTbl.ContactName, ClientTbl.Mobile,"
            + "ClientTbl.Email FROM RentalTbl INNER JOIN ClientTbl ON RentalTbl.ClientID = ClientTbl.ClientID"
            + "WHERE(RentalTbl.NumberPlate = @Param1)", conn);
            
            da.Fill(dt);

            singleHistoryDataGridView.DataSource = dt.DefaultView;

            conn.Close();
                  
        }
Posted
Comments
Richard C Bishop 4-Dec-12 10:40am    
Where is "@Param1" coming from? If you are meaning for it to be the string Param1 as in the code above, your WHERE clause should look like this:

Where (RentalTbl.NumberPlate = " + Param1 + ")",
tyska 4-Dec-12 10:47am    
i tried it still doesn't work.
DinoRondelly 4-Dec-12 10:40am    
Did you try putting @Param one in single quotes?
DinoRondelly 4-Dec-12 10:42am    
Where (RentalTbl.NumberPlate = '" + Param1 + "')", conn);
tyska 4-Dec-12 10:48am    
both ways, still same error

1 solution

Spaces, my friend, spaces. As in you need one between
ClientTbl.ClientID

and
WHERE(RentalTbl

C#
da = new SqlDataAdapter("SELECT RentalTbl.NumberPlate, RentalTbl.PricePD, RentalTbl.FromDate,"
+ "RentalTbl.ToDate, ClientTbl.CompanyName, ClientTbl.ContactName, ClientTbl.Mobile,"
+ "ClientTbl.Email FROM RentalTbl INNER JOIN ClientTbl ON RentalTbl.ClientID = ClientTbl.ClientID "
+ "WHERE(RentalTbl.NumberPlate = @Param1)", conn);
 
Share this answer
 
Comments
tyska 4-Dec-12 10:57am    
Thank you!!
OriginalGriff 4-Dec-12 11:11am    
You're welcome!
fjdiewornncalwe 4-Dec-12 11:03am    
+5. This one has bitten pretty much everyone who writes sql at some point.
OriginalGriff 4-Dec-12 11:11am    
Oh yes! And it's a PITA to see, because you end up reading what you meant to write! :laugh:

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