Link to home
Start Free TrialLog in
Avatar of spanish_fly

asked on

Adding column to a DataSet in C#.Net

I have a dataset with Day, month, and year as columns.  I want to add a new column called DT that adds all three columns. A similar question on has also been posted, but Im not getting any clue on how to proceed it in

The code is as follows for your kind reference :
Dim col As DataColumn = Me.DataSet1.Tables(0).Columns.Add("DT", GetType(DateTime))
        Dim i As Int32
        Dim rdr As iDB2DataReader
        rdr = cmd.ExecuteReader
        For i = 0 To Me.DataSet1.Tables(0).Rows.Count - 1
            Dim row As DataRow = Me.DataSet1.Tables(0).Rows(i)
            row("DT") = rdr("MONTH") + "/" + rdr("DAY") + "/" + rdr("YEAR")
        UltraGrid1.DataSource = DataSet1.Tables(0)
        '      Get the owners from the 'Employees' DataTable
        '      Get the notes from the 'Employees' DataTable

Open in new window

Avatar of p_davis

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of spanish_fly


Thanks a lot Davis.............tht helped me a lot..........!!!

I have changed the code according to my specifics. But I have something in continuation to the same. Now since I have got the new column created, how can i get the new column display on Crystal Report. At present let's say there are 5 fields being displayed on Crystal Report. And I'm using DataSet.xsd to represent those 5 fields, I can easliy fetch those fields since they are already present in database table. Now how will I add this column to DataSet.xsd..........or is tht not needed.............or, whts is the best way to represent the new column on Crystal Report alongwith the other 5 fields.

My code is as attached below:

DataSet newDS = new DataSet();
DataColumn dCol = new DataColumn(newDS.Tables[0].Columns.Add("DT", typeof(String)).ToString());
				for(Int32 i = 0; i < newDS.Tables[0].Rows.Count; i++)
					DataRow row = newDS.Tables[0].Rows[i];
				 	row["DT"] = row["CADMMM"].ToString() + "/" + row["CADMDD"].ToString() + "/" + row["CADMHH"].ToString() + "/" + row["CADMYY"].ToString();
// Create a CrystalReport1 object
				PIN_Crystal_Report myReport = new PIN_Crystal_Report();
				// Set the DataSource of the report
				// Set the Report Source to ReportView 
				crystalReportViewer1.ReportSource = myReport;

Open in new window

sorry but i don't use crystal reports and don't really know anything about them.
I appreciate your professionalism.............Good helped me a lot..........!!!