Click here to Skip to main content
16,006,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                binddata();
            }

        }
        private void binddata()
        {
            string connstring = @"Data Source=LENOVO-41B3F2CE\SQLEXPRESS;Initial Catalog=IMS;Integrated Security=True;Pooling=False";
            string query = "SELECT * FROM ['ISB VAS Nodes$']";
            SqlDataAdapter da = new SqlDataAdapter(query, connstring);
            DataTable dt = new DataTable();
            da.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
Posted
Updated 17-Apr-13 20:17pm
v2

Debug your code and check the number of rows in DataTable dt. It's because there is no rows in the DataTable your gridview is binding but not showing any records.


--Amit
 
Share this answer
 
Comments
kumar2413 18-Apr-13 2:44am    
You are right Amit.U have to check whether the datatable fill with value or not then only it will display.
While using DataAdapter following steps are followed:
1) Open a connection
2) Create a DataAdapter
3) Fill a table using DataAdapter
4) Bind table to GridView

Reference from below link:http://www.dotnetperls.com/sqldataadapter[^]

If above steps are followed, ensure the "AutoGenerateColumns" property of GridView is set to TRUE or you will need to define each column of the gridview. I think GridView should be visible using these steps. Please reply back if otherwise.
 
Share this answer
 
v2
try this:-

private void binddata()
        {
            string connstring = @"Data Source=LENOVO-41B3F2CE\SQLEXPRESS;Initial Catalog=IMS;Integrated Security=True;Pooling=False";
            string query = "SELECT * FROM ['ISB VAS Nodes$']";
            SqlConnection con = new SqlConnection(connstring );
            SqlCommand cmd = new SqlCommand(selectSQL, con);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);

            GridView1.DataSource = dt;
            GridView1.DataBind();
}
 
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