This tutorial show how to write the code connect to SQLServer database using C# Ado.net
Using the Connection Object
<% @Page Language="C#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <script language="C#" runat="server" > void Page_Load(Object src, EventArgs e){ String conStr = "Data Source=localhost;User Id=sa; Password=;Initial Catalog=northwind"; SqlConnection con = new SqlConnection(conStr); con.Open(); String sql = "Select employeeid, lastname, firstname From employees"; SqlDataAdapter adapter = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); adapter.Fill(ds, "Employees"); employees.DataSource = ds.Tables["Employees"]; employees.DataBind(); } </script> <html> <head></head> <body> <form runat="server" id=form1 name=form1> <asp:DataGrid id="employees" runat="server"></asp:DataGrid> </form> </body> </html>