Click here to Skip to main content
13,193,816 members (46,690 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: , +
Hello

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

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 14-Jun-12 0:51am
Updated 14-Jun-12 1:02am
krumia12K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Change
GridView1.DataSource = ds;

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


Make sure all the columns mapped in your grid is present in this table of your dataset used.
  Permalink  
Comments
Espen Harlinn 14-Jun-12 16:38pm
   
5'ed!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You might have a bound column which is bound to column "RequestID", but that is not in your tbl_SqlImage table
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.171018.2 | Last Updated 14 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100