Hello,
i have a Access database and am trying to create an aspx page from "lis_per" table which should be sortable by TeamID. I have written the following code and when i run it , it gives me "oledbexception was unhandled by usercode" pointing to the statement "dgrdpersons.DataSource = cmdselect.ExecuteReader()" in code. says syntax error in ORDER BY clause
System.Data.OleDb.OleDbException was unhandled by user code
ErrorCode=-2147217900
Message="Syntax error in ORDER BY clause."
Source="Microsoft JET Database Engine"
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at ASP.person_aspx.BindDataGrid(String strSortField) in C:\Documents and Settings\axb59274\Desktop\Access_Code_website\Person.aspx:line 18
at ASP.person_aspx.page_load() in C:\Documents and Settings\axb59274\Desktop\Access_Code_website\Person.aspx:line 6
at System.Web.Util.CalliHelper.ArglessFunctionCaller(IntPtr fp, Object o)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
The code is
<%
@ Import Namespace ="system.data.oledb" %><
script runat ="server" > Sub page_load() If Not IsPostBack ThenBindDataGrid(
"Lis_per") End If End Sub Sub BindDataGrid(ByVal strSortField As String) Dim conAccess As OleDbConnection Dim cmdselect As OleDbCommandconAccess =
New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Documents and Settings\axb59274\Desktop\PfE New Tables.mdb")conAccess.Open()
cmdselect =
New OleDbCommand("select PerID,Last,First,TeamID from lis_per Order By" & strSortField, conAccess)dgrdpersons.DataSource = cmdselect.ExecuteReader()
dgrdpersons.DataBind()
conAccess.Close()
End Sub Sub dgrdpersons_sortcommand(ByVal s As Object, ByVal e As DataGridSortCommandEventArgs)BindDataGrid(e.SortExpression)
End Sub</
script><
html xmlns="http://www.w3.org/1999/xhtml" ><
head runat="server"> <title>Untitled Page</title></
head><
body> <form id="form1" runat="server"> <div> <span style="font-size: 24pt"> <b> Person List</b> :</span> <asp:DataGrid ID = "dgrdpersons" AutoGenerateColumns ="False" EnableViewState ="False" AllowSorting ="true" OnSortCommand ="dgrdpersons_SortCommand" runat ="server" CellPadding="10" ForeColor="#333333" GridLines="None" > <Columns > <asp:BoundColumn DataField ="PerID" HeaderText = "ID" ></asp:BoundColumn> <asp:BoundColumn DataField ="Last" HeaderText= " Last Name" ></asp:BoundColumn> <asp:BoundColumn DataField ="First" HeaderText = "First Name " ></asp:BoundColumn> <asp:BoundColumn DataField ="TeamID" HeaderText ="Team" SortExpression = "TeamID" ></asp:BoundColumn> <asp:HyperLinkColumn HeaderText = "Details" DataNavigateUrlField = "PerID" DataNavigateUrlFormatString ="Per_Details.aspx id ={0}" Text = "View Details"></asp:HyperLinkColumn> </Columns> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <EditItemStyle BackColor="#999999" /> <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <AlternatingItemStyle BackColor="White" ForeColor="#284775" /> <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> </asp:DataGrid> </div> </form></
body></
html>can anyone helpme sort this issue, please.

sorting by teamID
George Hara
Looks like a space is missing after your "Order By" clause, which would result in the following: "Order ByLis_per"
Scott Boyd
If lis_per is your table name then shouldn't you be passing the column name that you want to sort by in the call to BindDataGrid
Vincent Fournier
Did you try setting debug breakpoints in your code to make sure that it is running properly At the moment I'm not seeing any other potential problems in the code.
sheldono
Are you sure the sort event handler is firing It looks like the Handles statement is missing:
Sub dgrdpersons_sortcommand(ByVal s As Object, ByVal e As DataGridSortCommandEventArgs) Handles dgrdpersons.SortCommand
Raj S
it makes no differnece with it, or without it. I tried it.
vijayshankark
I think you're missing some code, such as setting the SortExpression property of the column that has been clicked on. There's a good article that discusses how to handle sorting with the ASP.NET DataGrid:
http://aspnet.4guysfromrolla.com/articles/012903-1.aspx
Dugan Porter - Microsoft
yes i did that, but its directly giving me the list sorted by teamID. And here when i click "Team" it just vanishes entire data and give me a blank page
The headertext for teamID column is Team and i wated it in a way that when we click "Team" then only should the entire list be sorted by Team.
sbni
hello paul,
I checked the link u sent me. I have already done what it says. If you look at the code which i posted in my first post , all the design part is correct. may be something wrong in the way i binf the data. Is ther eanyother source where i could find the answer.
thx
Ahoapap
hello paul,
Thx for the reply. Now it gives a different oledbexception pointing to the same statement
"No value given for one or more required parameters." and the exception is
System.Data.OleDb.OleDbException was unhandled by user code
ErrorCode=-2147217904
Message="No value given for one or more required parameters."
Source="Microsoft JET Database Engine"
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at ASP.person_aspx.BindDataGrid(String strSortField) in C:\Documents and Settings\axb59274\Desktop\Access_Code_website\Person.aspx:line 18
at ASP.person_aspx.page_load() in C:\Documents and Settings\axb59274\Desktop\Access_Code_website\Person.aspx:line 6
at System.Web.Util.CalliHelper.ArglessFunctionCaller(IntPtr fp, Object o)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
and i am also confudes about these set of statements
Sub
page_load() If Not IsPostBack ThenBindDataGrid(
"Lis_per") End Iflis_per is my table name ,should it be there in the " " or shoud it be primary key of table or anything else.
I tried putting TeamID there , it directly gives me a page with the list sorted and when i click the header text "Team" it becomes a blank page
can u help me with this
THank you