C# ASP.NET ADO.NET JAVASCRIPT JQUERY AJAX SILVERLIGHT WPF
C# OOPS HTML&CSS DHTML ASP.NET ADO.NET JAVASCRIPT JQUERY AJAX SILVERLIGHT MVVM WPF SQL SERVER Photoshop Dreamweaver Flash Illustrator
Blog Archive
-
2012
(83)
- September(2)
-
August(81)
- Important WPF Classes and Namespaces
- Applications of WPF
- Programming With WPF
- Limitations of Silverlight and flash
- Silverlight Feature comparison with Flash Features
- How to Add XML File in Your Silverlight Project
- 3 Pixel Shader Effects in Silverlight
- Rotate Image in 3D direction using Silverlight
- First Application of Silverlight
- Silverlight 2.0
- How Install Ajax?
- Ajax Advantage
- JavaScript Loops
- Show a Military Clock and ordinary clock
- How To validate a Form in ASP. Net
- How to show Day of Week
- How to Swap a Image using JavaScript
- Special Character in JavaScript
- Prompt Box in JavaScript
- The use of data adapter.?
- The steps involved to fill a dataset?
- Dataset object in ADO .NET
- Handling Connection Events
- The SQLCONNECTION OBJECT
- Command Constructors
- The SQLCOMMAND OBJECT
- Gridview in ASP.NET
- Introduction Of Master Page
- Server Side State Management
- Query String In ASP.NET
- Cookies in ASP.NET
- State Management in ASP.NET
- Various types of application that we can develop i...
- Properties
- Inheritance ,Polymorphism
- Array,Indexer and Collections
- Control Statements
- Operators, types and variables in C#
- Fundamental of C#
- C# & other Programming Languages
- The WPF Designer
- C# DataTypes
- What is Ajax?
- Silverlight 1.0
- Confirm Box in JavaScript
- Component classes
- Life Cycle of ASP.NET
- The Basics of JQuery
- Jquery Blog Content
- Birth Of WPF
- .Net Frameworks Architecture
- History Of Ajax
- Why Silverlight?
- How to access a URL of parent page in ASP. net
- THE ADO.NET Architecture?
- Architecture of ASP.NET
- Introduction Of Ajax
- Ajax Blog Content
- Introduction of SilverLight
- Silverlight Blog Content
- Introduction to Javascript Blog
- Javascript Blog Content
- Introduction to Ado.Net blog
- Ado.Net Blog Content
- Introduction to C# Blog
- C# Blog Content
- Introduction to Asp.Net
- Asp.Net Blog Content
- Introduction to WPF
- WPF Blog Content
- WPF Interview Question
- Silverlight Interview Question
- Ajax Interview Question
- JQuery Interview Question
- Javascript Interview Question
- DHTML Interview Question
- Ado.Net Inetview Questions
- SQL Interview Questions
- HTML&CSS Interview Questions
- Asp.Net Interview Qusetions
- C# Interview Questions
The SQLCONNECTION OBJECT
The SQLCONNECTION OBJECT
A SqlConnection is an object,as any other C# object. we just declare and instantiate the SqlConnection all at the same time, as shown below:
SqlConnection con = new SqlConnection(
"Data Source=(local);Initial Catalog=Emp;Integrated Security=sspi");
The SqlConnection object instantiated above by using a constructor with a single argument of type string and this argument is called a connection string.
There are four Connection String Parameter Name:-
1)Data Source: Data Source Identifies the server and it Could be local machine, machine domain name, or IP Address.
2)Initial Catalog: Database name
3)Integrated Security: Integrated Security set to SSPI to make connection with user's Windows login.
4)User ID: Name of user configured in SQL Server.
5)Password: Password matching SQL Server User ID.
The following shows a connection string, using the User ID and Password parameters:
SqlConnection conn = new SqlConnection(
"Data Source=DatabaseServer;Initial Catalog=Northwind;User ID=YourUserID;Password=YourPassword");
Using a SqlConnection
The aim of creating a SqlConnection object is so we can enable other ADO.NET code to work with a database and SqlCommand and a SqlDataAdapter take it a connection object as a parameter. The sequence of operations occurring in the lifetime of a SqlConnection are given below:
- Instantiate the SqlConnection.
- Open the connection.
- Pass the connection to other ADO.NET objects.
- Perform database operations with the other ADO.NET objects.
- Close the connection.
The Open() Method:
The Open() method of the Connection object establishes a connection to the data source.,because database connections are a very expensive resource memory-wise, so we should only call the Open() method just before we're ready to retrieve the data. This ensures that the connection is not open any longer than it needs to be.
The Close() Method
After we are done retrieving data,we should call the Close() method of the Connection object. This closes the connection to the database.
Example Using SQLCONNECTION Object
using System;
using System.Data;
using System.Data.SqlClient;
class sqlConnectivityexample
{
static void Main()
{
SqlConnection conn = new SqlConnection(
"Data Source=(local);Initial Catalog=Emp;Integrated Security=SSPI");
SqlDataReader rdr = null;
try
{
// 2. Open the connection
conn.Open();
// 3. Pass the connection to a command object
SqlCommand cmd = new SqlCommand("select * from emp", conn);
//
// 4. Use the connection
//
// get query results
rdr = cmd.ExecuteReader();
// print the CustomerID of each record
while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}
// 5. Close the connection
if (conn != null)
{
conn.Close();
}
}
}
}
|









