Dataset problem

X

xzzy

Dotnet v1.1

The following code creates a dataset with

- the correct number of rows
- the information in COL1 and COL2 are correct
- but the dataset only has 2 columns, COL1 and COL2


What is wrong??


Thank you,

John


private bool MakeDataset(SqlDataReader xReader)
{
bool result = false;
try
{
System.Web.HttpContext.Current.Session.Remove("MyDataSet");
DataSet ds = new DataSet();
DataTable dt = new DataTable("MyData");
DataRow dr;
dt.Columns.Add(new DataColumn("COL1", typeof(Int32)));
dt.Columns.Add(new DataColumn("COL2", typeof(System.DateTime)));
dt.Columns.Add(new DataColumn("COL3", typeof(string)));
dt.Columns.Add(new DataColumn("COL4", typeof(string)));
dt.Columns.Add(new DataColumn("COL5", typeof(string)));
dt.Columns.Add(new DataColumn("COL6", typeof(string)));
dt.Columns.Add(new DataColumn("COL7", typeof(string)));
dt.Columns.Add(new DataColumn("COL8", typeof(System.DateTime)));

while (xReader.Read())
{
dr = dt.NewRow ();
dr["COL1"] = Convert.ToInt32(xReader.GetValue(0));
dr["COL2"] = Convert.ToDateTime(xReader.GetValue(1));
dr["COL3"] = xReader.GetValue(2).ToString();
dr["COL4"] = xReader.GetValue(3).ToString();
dr["COL5"] = xReader.GetValue(4).ToString();
dr["COL6"] = xReader.GetValue(5).ToString();
dr["COL7"] = xReader.GetValue(6).ToString();
dr["COL8"] = Convert.ToDateTime(xReader.GetValue(7));
dt.Rows.Add (dr);
}
ds.Tables.Add(dt);
System.Web.HttpContext.Current.Session["MyDataSet"] = ds;
result = true;
}
catch (Exception ex)
{
}
return result;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top