Click here to Skip to main content
15,904,638 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
 query = "select Region,Service_Provider,File_Name from Upload_Cdr_Detail where Case_Name='" + Session["case_name"].ToString().Trim() + "'";
DataTable dt1 = data_obj.SelectTableValue(query, "Upload_Cdr_Detail");

GridView1.DataSource = dt1;
GridView1.DataBind();

There is DAtaTable giving proper result. But GridView1.DataBind() is giving Error.
Error : A field or property with the name 'Id' was not found on the selected data source.

What I have tried:

Why giving Error and how to remove it?
Posted
Updated 4-Jun-16 1:32am

Two things:
First, never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. Particularly on a web based solution where anyone in the world has access...

Secondly, the error message is very explicit:
A field or property with the name 'Id' was not found on the selected data source
Since your SELECT statement doesn't return an ID field, you need to look at how you have set up the GridView to find out why it is trying to access a column with that name. Or add the ID to the SELECT...
 
Share this answer
 
problem is in your query you are not fetch id from database.
check bellow. solution

C#
 query = "select Id,Region,Service_Provider,File_Name from Upload_Cdr_Detail where Case_Name='" + Session["case_name"].ToString().Trim() + "'";
DataTable dt1 = data_obj.SelectTableValue(query, "Upload_Cdr_Detail");
 
GridView1.DataSource = dt1;
GridView1.DataBind();


or


C#
query = "select * from Upload_Cdr_Detail where Case_Name='" + Session["case_name"].ToString().Trim() + "'";
DataTable dt1 = data_obj.SelectTableValue(query, "Upload_Cdr_Detail");
 
GridView1.DataSource = dt1;
GridView1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900