Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Quote:
I have this method in DAL file.

C#
public DataView select_data()
    {
        cmd = new SqlCommand("profile_select",cnn);
        cmd.CommandType = CommandType.StoredProcedure;

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        DataView dv = new DataView();
        dv.Table = ds.Tables[0];
        return dv;
    }  


this is in code behind file (profile.aspx.cs).
C#
public void bindgrid()
   {
       dv=objdal.select_data();
       GridView1.DataSource = dv;
       GridView1.DataBind();

   }


If I want to use datatable inplace of dataset and dataview ,then how to use datatable?

please help me for this.
Posted
Updated 20-Dec-12 19:31pm
v2

you can use like this in your code and can bind datatable with GridView
public DataTable select_data()
{
   cmd = new SqlCommand("profile_select",cnn);
   cmd.CommandType = CommandType.StoredProcedure; 
   SqlDataAdapter da = new SqlDataAdapter(cmd);
   DataTable dt=new DataTable()
   da.Fill(dt);
   return dt;
}
 
Share this answer
 
v2
C#
// DAL
public DataTable select_data()
    {
        cmd = new SqlCommand("profile_select",cnn);
        cmd.CommandType = CommandType.StoredProcedure;
 
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
 
        return dt;
    }

Aspx.cs
C#
public void bindgrid()
   {
       DataTable dt=objdal.select_data();
       GridView1.DataSource = dt;
       GridView1.DataBind();

   }
 
Share this answer
 
v2
try this

C#
public void bindgrid()
   {
       cmd = new SqlCommand("profile_select",cnn);
       cmd.CommandType = CommandType.StoredProcedure;
       SqlDataAdapter da = new SqlDataAdapter(cmd);
       DataTable dt = new DataTable();
       da.Fill(dt);
      
       GridView1.DataSource = dt;
       GridView1.DataBind();

   }
 
Share this answer
 
v2

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