its been 6 days passed since i started making this assignment of mine
it is to show how objectdatasource is used,

until now, i still cannot getaway with this error,

The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content.

is anybody can help me? and check what is wrong with my codes?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="background-color: #FFCC00" >
        &nbsp;<asp:GridView 
            ID="GridView1" runat="server" DataSourceID="ObjectDataSource1">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="pID" />
                <asp:BoundField DataField="firstname" HeaderText="firstName" />
                <asp:BoundField DataField="lastname" HeaderText="lastName" />
                <asp:BoundField DataField="age" HeaderText="age" />
                <asp:BoundField DataField="contact" HeaderText="contact" />
                <asp:BoundField DataField="address" HeaderText="address" />
                <asp:BoundField DataField="email" HeaderText="email" />
            </Columns>
        </asp:GridView>
&nbsp;<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="select" TypeName="yaxclas" 
            >
        </asp:ObjectDataSource>

    </div> <br />

<div  style="background-color: #800000"> 
        <asp:Button ID="btn_prev" runat="server" Text="previous page" Font-Bold="True" 
            onclick="btn_prev_Click" /> 
    </div>
    

    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// simple class with select method to be connected
///  to the objectdatasource
/// </summary>
public class yaxclas
{
    int id;
    int age;
    int contact;
    string email;
    string address;
    string firstname;
    string lastname;
    

    public yaxclas()
	{
		
	}

    public yaxclas select() 
    {
       yaxclas yxperson = new yaxclas();

      

      string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;

        SqlConnection con = new SqlConnection(ConnectionString);

        string queryString ="SELECT * FROM person;";
        
       try
       {
            con.Open();
            SqlCommand cmd =  new SqlCommand(queryString, con);
            cmd.CommandType = CommandType.Text;
            SqlDataReader reader = cmd.ExecuteReader();


           if(reader.Read())
                   {
                        yxperson.id = (int)reader["pID"];

                        yxperson.firstname = reader["firstName"].ToString();
                        yxperson.lastname = reader["lastName"].ToString();
                        yxperson.age = (int)reader["age"];
                        yxperson.contact = (int)reader["contact"];
                        yxperson.address = reader["address"].ToString();
                        yxperson.email = reader["email"].ToString();
                  }
       }
        finally
        {
                
                con.Close();
        }

       return yxperson;
       
    }
}

Create Properties for the above fields you declared it will work

like example below:

int mid;

public int Mid
{
    get { return mid; }
    set { mid = value; }
}

ahww...i haven't thought of creating setters and getters :-D

Thank you very much shravan24

i've got to try this one

why am i having this error?
An unhandled exception of type 'System.StackOverflowException' occurred in App_Code.7fwkmzwo.dll

it pointed somewhere in the bold letters below

public int id 
    {
        set { this.Id = id; }
       [B] get { return id; }[/B]
    }

it already worked, i just changed my properties from

public int id 
    {
        set { this.Id = id; }
        get { return id; }
    }

to something like this

public int Id 
    {
        get { return this.id; }
        set { id=value; }
    }

thank you very much, thank you for this site

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.