Click here to Skip to main content
15,889,992 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)
    {
        string connection = System.Configuration.ConfigurationManager.ConnectionStrings["itax1"].ConnectionString;
        SqlConnection con = new SqlConnection(connection);       
        con.Open();
        SqlDataAdapter da;
        da = new SqlDataAdapter("Select * from pa_salary_master", con);
        da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        }

i got this error
The SelectCommand property has not been initialized before calling 'Fill'.


here data is align horigentally but i nedd vortically. how to align vartically.
Posted
Updated 24-May-12 0:15am
v4
Comments
uspatel 24-May-12 5:47am    
pre tag added

C#
SqlDataAdapter da;
da = new SqlDataAdapter("Select * from pa_salary_master", con);
da = new SqlDataAdapter();

use only singe adapter.
C#
ie. da = new SqlDataAdapter("Select * from pa_salary_master", con);

Remove da = new SqlDataAdapter();
&
Remove con.Open();
 
Share this answer
 
v5
Comments
Nilesh Patil Kolhapur 24-May-12 5:55am    
nice
sharmarun 29-May-12 6:22am    
my 5!
Replace your code with this

protected void Page_Load(object sender, EventArgs e)
{
        string connection = System.Configuration.ConfigurationManager.ConnectionStrings["itax1"].ConnectionString;
        SqlConnection con = new SqlConnection(connection);     
        SqlDataAdapter da;  
        DataSet ds = new DataSet();
        using(da = new SqlDataAdapter("Select * from pa_salary_master", con))
        {
         da.Fill(ds);
        }
        GridView1.DataSource = ds;
        GridView1.DataBind();
}
 
Share this answer
 
v4
Comments
Killzone DeathMan 24-May-12 6:29am    
It works, but... I personally don't like the code: "using" because I use the code "using" in the top to call an library example: "using System.Windows.Forms;"!
You have reinitialized da. and the new da dont have select command text initialized
just remove the line
C#
da = new SqlDataAdapter();

also you dont need to open the connection here
adapter will manage it.
so also remove
C#
con.Open();
 
Share this answer
 
v2
Comments
Killzone DeathMan 24-May-12 6:26am    
It´s better open() the connection and in the end close() it!

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