Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 1:51am
Edited 14-Jun-12 2:02am
krumia11.9K
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 at 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
0 Sergey Alexandrovich Kryukov 380
1 OriginalGriff 230
2 DamithSL 220
3 Zoltán Zörgő 150
4 Maciej Los 135
0 OriginalGriff 7,740
1 DamithSL 5,694
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,061
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 14 Jun 2012
Copyright © CodeProject, 1999-2014
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