Property Name with 'Name' cannot be found on selected datasource! [Resolved]

Posted by Laghaterohan under Regular Expressions on 12/13/2010 | Points: 10 | Views : 5277 | Status : [Member] | Replies : 2
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



Responses

Posted by: Laghaterohan on: 12/13/2010 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,
Thanks for the reply,
I WAS GETTING ERROR DUE TO MY SILLY MISTAKES...:(

Best Regards,
Rohan Laghate

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 12/13/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
@Laghaterohan,

This might be coming because the "Name" doesn't found in the datasource( DataTable), try by not declaring the columns name in the GridView something like

<asp:GridView ID="GridView1" runat="server" />


And then set the DataSource, see what is the column name coming by default when you are running your app and then accordingly explicitly declare the columns of the GridView.

By the way, are you using http://www.csvreader.com/code/cs/gridview.php to read the csv?

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response