Something simple, you want to use ADO.NET to bind data from SQL Server to a GridView, here is your code behind
[codesyntax lang=”csharp”]
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string conn = ConfigurationManager.ConnectionStrings["STRINGNAME"].ConnectionString; SqlConnection con = new SqlConnection(conn); using (con) { SqlCommand cmd = new SqlCommand("SELECT * FROM Table", con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); gv.DataSource = rdr; gv.DataBind(); } } }
[/codesyntax]
Here is your control
[codesyntax lang=”csharp”]
<asp:GridView ID=”gv” runat=”server” />
[/codesyntax]