Click here to Skip to main content
11,720,785 members (76,095 online)
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 0:51am
Edited 14-Jun-12 1: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 2,179
1 OriginalGriff 924
2 F-ES Sitecore 640
3 Maciej Los 609
4 Richard MacCutchan 540


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