Accessing the database using ADO

Source: Internet
Author: User

Property Description
ConnectionString Set/Get Application connection string
Method Description
void Open ()

To open a database connection using the settings specified by the ConnectionString property

void Close () To close a connection to a database

2. Define the connection string

String sqlcon= "Data source=.;i Nitial Calalog=myschool; User Id=sa; Pwd=. ";

2.2 Creating a Connection object

SqlConnection con=new SqlConnection (Sqlcon);

3.1 When handling exceptions

Try
{
Code that might have occurred an exception
Con. Open ();
}
catch (Exception ex)
{
Catching exceptions
Console.WriteLine (ex);
}
Finally
{
Con. Close ();
will always be executed.
}

5.Command
Command cmduser=new command ();
cmduser.commandtext= "Select username,useraddr from Tbluser";
CMDUSER.CONNECTION=CN;
1. Open the database connection
cn. Open ();
Reader=cmduser.executereader ();
2. Close the database connection
Reader. Close ();
cn. Close ();

Accessing the database using ADO

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.