Introduction to ADO. NET Data Access Technology

Source: Internet
Author: User
Tags microsoft sql server management studio

Example of accessing SQL Server using ADO. NET

First inMicrosoft SQL Server Management StudioTestT-SQLStatement. In the following exampleT-SQLStatement.

Select * FromEmployeesWhereEmployeeidBetween2And 6  

The query result is as follows:

So we are usingC #How to complete the data access function in the code when building an application. See the sample code:

Sample CodeA:

Using System;

Using System. Data;

Using System. Data. SqlClient;


Namespace SqlServerProvider

{

Class Program

{

Static void Main (string [] args)

{

// Set the connection string

String connString = @"

Server = .;

Integrated Security = True;

Initial Catalog = Northwind

";

// Set the query string in hard encoding Mode

String sqlqry = @ "select * from employees where employeeid between 2 and 6 ";

// Declare the data connection and data reader object variables

SqlConnection conn = null;

SqlDataReader reader = null;

Try

{

Conn = new SqlConnection (connString );

SqlCommand restart qry = conn. CreateCommand ();

Repeated qry. CommandType = CommandType. Text;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.