Play-Asia.com - Buy Video Games for Consoles and PC - From Japan, Korea and other Regions!

C# - Data Access with ADO.NET

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>
 
 
Visitor Review Write a review
No visitor review for this page yet
Write a review
Rating:
Text:
Name:
Email:
(optional)
 
Code:
 

Search:
Shopping Store Online
Clothes (25)
Gift shop (69)
Hand-made (27)
Luxuries (47)
Others (42)
Programming Tutorial
ASP (14)
CSharp
Binding Data to List Control
Data Access with ADO.NET
DataGrid Control
The ArrayList class
The BitArray Class
The Calendar Class
The Hashtable Class
The HttpCookie Class
The HttpRequest Class
The HttpResponse Class
The Queue Class
The Repeater List Control
The SortedList Class
The SqlCommand Class
The SqlConnection Class
The SqlDataReader Class
The SqlParameter Class
The SqlParameterCollection Class
The SqlTransaction Class
HTML (10)
JavaScript (6)
Photoshop (9)
PHP (11)
Entertainment
Anime (6)
E-Cards (12)
Games (20)
Music (7)