Hello,
I am creating a datatable from a csv file and binding it to the gridview i am using following code for it..
MY CSV FILE CONTAINS TWO COLUMNS NAME AND PLACE WITH THE RESPECTIVE DATA BELOW THE COLUMNS EG.
NAME PLACE
ABC XYZ
PQR 123
private void _ReadCSV()
{
try
{
//create object for CSVReader and pass the stream
CSVReader reader = new CSVReader(FileUpload1.PostedFile.InputStream);
//get the header 28:
string[] headers = reader.GetCSVLine();
DataTable dt = new DataTable();
//add headers
foreach (string strHeader in headers)
{
dt.Columns.Add(strHeader );
}
string[] data;
while ((data = reader.GetCSVLine()) != null)
{
dt.Rows.Add(data);
}
GridView1.DataSource = dt;
GridView1.DataBind(); // A field or property with the name 'NAME' was not found on the selected data source.
}
I CHECKED WITH DT.DEFAULTVIEW ALSO HOWEVER, I AM STILL GETTING THE ERROR....
WHERE AM I WRONG...PLEASE CORRECT ME...
THANKS!
Best Regards,
Rohan Laghate