
Configure the SQL DataSource as per the below diagram.If in the server name 'Localhost' doesn't exist, type 'localhost' manually and check the database name, if it shows the database name you can select the proper database, where you have created the tables. If it doesn't shows the database name select the proper server name from the server name dropdown list and try the same.



Here 'users' is the Table name which belongs to Master DataBase.
public partial class _Default : System.Web.UI.Page
{
string conn;
SqlConnection con;
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
conn = "Data Source=LOCALHOST;Initial Catalog=master;Integrated Security=True";
con = new SqlConnection(conn );
con.Open();
da = new SqlDataAdapter("select * from users", con);
ds = new DataSet();
da.Fill(ds);
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
No comments:
Post a Comment