Sorting Datagrid problem

  • Thread starter Thread starter Pat
  • Start date Start date
P

Pat

I'm trying to do a sorting in a Datagrid below but i'm getting
ERRROR:- "Line 1: Incorrect syntax near 'CompanyID'."
strQuery = "Select InvoiceDate,OrderDate From CMRC_Orders ORDER BY " & _
viewstate("sortField").ToString & "" & _
viewstate("sortdirection") & "" & _
"where CompanyID = " & myDropDownList.SelectedItem.Value

Any ideas 'm passing the DropDwon Selected value because thats what i use to
populate the Datagrid
 
Um..it is hard to tell because of the formatting of the post..

Here goes..

1) When using dynamic Sql ..it is a good thing to Response.Write the Query
to make sure it is getting all the values required to run successfully..

2) It also gives an indication of any formatting errors in the query ie:
missing commas, spaces ect.

It could be the formating in the post but you could be missing some
spaces...
A "" may not provide the space provided by " ".

Failing that check your value parameters.

Also you haven't specified a rdbms which is usually helpful when dealing
with sql problems.
I am assuming SQL Server..

Cheers,
Adam
Ps: So where are you from?
 
Hi Pat,

Are you missing the quote for the CompanyID value?

Regards,
Jack Li
MVP (ASP.NET)
 
I'm trying to do a sorting in a Datagrid below but i'm getting
ERRROR:- "Line 1: Incorrect syntax near 'CompanyID'."
strQuery = "Select InvoiceDate,OrderDate From CMRC_Orders ORDER BY " & _
viewstate("sortField").ToString & "" & _
viewstate("sortdirection") & "" & _
"where CompanyID = " & myDropDownList.SelectedItem.Value

Any ideas 'm passing the DropDwon Selected value because thats what i use
to
populate the Datagrid

Er, unless I'm missing something blindingly obvious...

1) you don't have spaces in your SQL - change "" to " "
2) you've got your ORDER BY clause before your WHERE clause...
 
Thx guys
My ORDER BY clause was before WHERE


Mark Rae said:
Er, unless I'm missing something blindingly obvious...

1) you don't have spaces in your SQL - change "" to " "
2) you've got your ORDER BY clause before your WHERE clause...
 
Back
Top