here is my coding
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;
namespace adapter
{
public partial class _Default : System.Web.UI.Page
{
public SqlConnection con = new SqlConnection();
public SqlCommand cmd = new SqlCommand();
public SqlDataAdapter sda = new SqlDataAdapter();
public SqlDataReader sdr;
public DataTable myDataTable = new DataTable();
public String constr, cmdstr;
protected void Page_Load(object sender, EventArgs e)
{
constr = @"Data Source=RAHUL-PC\SQLEXPRESS;Initial Catalog=a1;Integrated Security=True";
con = new SqlConnection(constr);
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
cmd=new SqlCommand("select * from details",con);
sda=new SqlDataAdapter(cmd);
sda.Fill(myDataTable);
GridView2.DataSource = myDataTable;
GridView2.DataBind();
con.Close();
}
}
}
Sandeep Singh ShekhawatPosted Dec 8, 2012, 8:50 AM
constr = @"Data Source=RAHUL-PC;Initial Catalog=a1;Integrated Security=True";
all code is okay.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class adapter : System.Web.UI.Page
{
public SqlConnection con = new SqlConnection();
public SqlCommand cmd = new SqlCommand();
public SqlDataAdapter sda = new SqlDataAdapter();
public SqlDataReader sdr;
public DataTable myDataTable = new DataTable();
public String constr, cmdstr;
protected void Page_Load(object sender, EventArgs e)
{
constr = @"Data Source=RAHUL-PC;Initial Catalog=a1;Integrated Security=True";
con = new SqlConnection(constr);
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("select * from details", con);
sda = new SqlDataAdapter(cmd);
sda.Fill(myDataTable);
GridView2.DataSource = myDataTable;
GridView2.DataBind();
con.Close();
}
}
Vishnujeet KumarPosted Dec 8, 2012, 8:43 AM
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace adapter
{
public partial class _Default : System.Web.UI.Page
{
public SqlConnection con ;
public SqlCommand cmd ;
public SqlDataAdapter sda;
public SqlDataReader sdr;
public DataTable myDataTable = new DataTable();
public String constr, cmdstr;
protected void Page_Load(object sender, EventArgs e)
{
constr = @"Data Source=RAHUL-PC\SQLEXPRESS;Initial Catalog=a1;Integrated Security=True";
con = new SqlConnection(constr);
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
sda = new SqlDataAdapter("select * from details", con);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
con.Close();
}
}
}
one Example :
http://www.aspdotnet-suresh.com/2012/05/bind-data-to-dropdownlist-in-gridview.html