Question : datareader to dataset

I am trying to convert a datareader to a dataset, but I get an error in this line:

dataRow[cntr] = reader.GetValue(cntr);

error message: http://www.experts-exchange.com/newQuestionWizard.jsp
Ask a Question Wizard

Type of value has a mismatch with column typeCouldn't store <34521> in PROJECT_ID Column. Expected type is DataRow.

here is the method
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
public DataSet ConvertDataReaderToDataSet(OleDbDataReader reader)
        {
            DataSet dataSet = new DataSet();
            DataTable schemaTable = new DataTable();
            schemaTable =  reader.GetSchemaTable();
            DataTable dataTable = new DataTable();
 
            for (int cntr = 0; cntr < schemaTable.Rows.Count; ++cntr)
            {
                DataRow dataRow = schemaTable.Rows[cntr];
                string columnName = dataRow["ColumnName"].ToString();
                DataColumn column = new DataColumn(columnName, dataRow.GetType());
                dataTable.Columns.Add(column);
            }
 
            dataSet.Tables.Add(dataTable);
 
            while (reader.Read())
            {
                DataRow dataRow = dataTable.NewRow();
                for (int cntr = 0; cntr < reader.FieldCount; ++cntr)
                {
                    dataRow[cntr] = reader.GetValue(cntr);
                }
            }
Open in New Window Select All

Answer : datareader to dataset

here is how you are supposed to use the data row:  http://msdn.microsoft.com/en-us/library/system.data.datarow(VS.71).aspx
Random Solutions  
 
programming4us programming4us