Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello

Plz help
I have this code for gridview data bind.
I have one row in table

C#
protected void Page_Load(object sender, EventArgs e)
        {
            

            string connection = "Data Source=ip;Initial Catalog=commonlogin;User ID=sa;Password=; ";


            SqlConnection conn = new SqlConnection(connection);
            conn.Open();
            SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM tbl_SqlImage", conn);
            //SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_SqlImage", conn);
            //SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            ad.Fill(ds);
            if (ds.Tables[0].Rows.Count != 0)
            {
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }


I get following error:

A field or property with the name 'RequestID' was not found on the selected data source.

Plz help
Posted
Updated 14-Jun-12 1:02am
v2

Change
C#
GridView1.DataSource = ds;

to
C#
GridView1.DataSource = ds.Tables[0];


Make sure all the columns mapped in your grid is present in this table of your dataset used.
 
Share this answer
 
Comments
Espen Harlinn 14-Jun-12 16:38pm    
5'ed!
You might have a bound column which is bound to column "RequestID", but that is not in your tbl_SqlImage table
 
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