- protected void Write_CSV_From_Recordset2(SqlDataReader oDataReader)
- {
- StringBuilder builder = new StringBuilder();
- List<string> columnNames = new List<string>();
- List<string> rows = new List<string>();
-
- for (int i = 0; i < oDataReader.FieldCount; i++)
- {
- string tmpColumnName = oDataReader.GetName(i);
-
- columnNames.Add(tmpColumnName);
- }
-
- builder.Append(string.Join(",", columnNames.ToArray())).Append("\n");
-
- List<string> currentRow = new List<string>();
-
-
- while (oDataReader.Read())
- {
-
-
- for (int i = 0; i < oDataReader.FieldCount; i++)
- {
- object item = oDataReader[i];
-
-
- currentRow.Add(item.ToString());
-
-
-
- }
-
-
-
-
- }
-
-
-
- rows.Add(string.Join(",", currentRow.ToArray()));
- builder.Append(string.Join(",", rows.ToArray())).Append("\n");
-
- Response.Clear();
- Response.ContentType = "text/csv";
- Response.AddHeader("Content-Disposition", "attachment;filename=pretestscore.csv");
- Response.Write(builder.ToString());
- Response.End();
- }
The problem is that :
while output is coming problem that means while (oDataReader.Read())
function the value are coming just like 281063,70,7091,85,TEST,200,test,NULL
. how to get actually data from the table? Where is the wrong in my code? any suggestion?