Why Crystal Report is Sorted Alphabetic wise Automatically?

yousuf42

Well-known member
Joined
Feb 12, 2006
Messages
101
Programming Experience
1-3
Dear All,

Why Crystal Reports Sorts Automatically? I use following code to assign dataset to the report. When the report generated everytime it sorts automatically. How can I remove auto sort?

Dim sql As String = "SELECT ProductID,ProductName,ProductImage FROM Products Where ProductID in (" & lstitems & ")"
Dim con As New OleDbConnection(conString)

Thanks

 
Sort your records in the report

Sort your records in any order you like in the report.
Right click on the report, select =>REPORT=>SORT RECORDS.
 
Thanks Dear Kulrom and DavidT,

Now I wanted to sort items as in the listbox using listbox.index. How can I do this? Below is the statement I'm using to fetch the data.

VB.NET:
Dim i AsInteger
lstPartNo2.SelectedIndex = 0
lstitems = """" & lstPartNo2.SelectedItem.ToString & ""
For i = 1 To lstPartNo2.Items.Count - 1
lstPartNo2.SelectedIndex = i
lstitems = "" & lstitems & """,""" & lstPartNo2.SelectedItem.ToString & ""
Next
lstitems = lstitems & """"
Dim sql AsString = "SELECT ProductID,ProductName,ProductImage FROM Products Where ProductID in (" & lstitems & ")"
Dim con AsNew OleDbConnection(conString)

Can you show me where I should add "orderby lstPartNo2.Index" Field?.

Thanks a lot in advance
 
Last edited by a moderator:
I may have to let Kulrom field this one.
I'm not sure what you are doing here.
You are creating a string containing all the items of the listbox to use in your SQL. (Your loop should be from 0 to count - 1) presumably to sort on.

I think you want to have your table sorted in the same order as the listbox?
I envision the user filling the listbox with the items he/she wants, and you want a report of those items in the order the user entered them?

Just thinking out loud here: You may have to load each part from the listbox seperately(sql where PartId = lstPartNo2.SelectedItem.ToString). Then add each record to a new table along with the listbox (index number + 1) (or i+1 in the loop) as a additional field. Use that table in crystal reports and sort based on the index number to get the same order as the listbox.
It will come down to you adding an integer field to a table of the Parts that will match the order in the listbox.

Is that even close to what you are looking for?

Let's see who comes up with an easier way...this way is not all that simple, huh?
 
Thanks Mr. DavidT,

Yes I want to have all records of the dataset to be sorted in the same order as the list box.

Or atleast I wanted to stop auto sort of the dataset.

Now it is sorted out alphabetic Asc order automatically, though I did not give any sort order in my statement.

Thanks a lot for your help.
 
Back
Top