| 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