Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to convert Arraylist to dataset and then set the dataset to the crystal report
. In data set i have "Total" field as extra column which will be calculated during the program execution time,also which is not in the database . How to show the total column in the crystal report...Please help me...Thank you for your precious time....
Posted
Updated 21-Nov-12 0:15am
v2
Comments
Mohd. Mukhtar 21-Nov-12 6:17am    
What have you tried so for??
Bhushan Shah1988 21-Nov-12 6:30am    
what is your problem?

1 solution

It sounds like you need to do some research. Here are the MSDN links to the objects you are working with:
DataSet[^]
DataTable[^]
ArrayList[^]

First of all, a DataSet is a collection of DataTables. When you say you have a column in your DataSet, you probably really mean that you have a DataTable in your DataSet and that DataTable has the columns.

Now, in order to "convert" the data from your ArrayList you will have to loop through the ArrayList and add each item into the DataTable that is contained in your DataSet. You can create the loop using a For Each statement. Here is a sample (It's in VB.Net, but you should be able to get the idea and convert to C# pretty easily):
VB
Dim myDataSet As New DataSet
Dim myDataTable As New DataTable
myDataTable.Columns.Add("Column1")
myDataSet.Tables.Add(myDataTable)

Dim myArrayList As New ArrayList

'Code that puts data into your array list would go here

'Here is the For Each loop.  It will loop through each object in the ArrayList
For Each obj As Object In myArrayList
    Dim rowNew As DataRow = myDataTable.NewRow 'Creates a new row that has the same schema as the myDataTable object
    rowNew("Column1") = obj.ToString 'Takes the object in the array list and puts it in a new row
    myDataTable.Rows.Add(rowNew) 'Adds the new row to myDataTable
Next

If you have other columns in your DataTable, you'll have to fill those as well. Also, depending upon the data type of your columns and what data you are filling your ArrayList with you may have to convert the objects in your ArrayList into the proper data type.

As for getting the total to appear in your crystal report, you will have to edit the report file itself to include your new field. You may have to setup groups if you want group totals or you may have to setup a page or report footer. You'll want to do some research either by google or through articles here on Code Project to research how to do that.

Hope this helps.
 
Share this answer
 

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