Monday, August 4, 2014





There are 6 easy steps to connect with database in asp.net and c#.net using ado.net




    1.Declare the Namespace
    2.Create the Connection 
    3.Open the Connection
    4.Pass the Query
    5.Execute the Connection 
    6.Close the Connection



1.Declare the Namespace


While connecting Microsoft sql server database in asp.net or c#.net. we have to declare the Namespace fisrst
That is..
using System.Data;
using System.Data.sqlclient;

2.Create the connection
 We can create the connection using following statement

 sql Connection con=new sql Connection("user id=sa;password=abc;database=write the database;data source=pc name/IP address");
in above code con is an object of an sql Connection class and new is a keyword which will allocate the memory to that object.
3.Open the Connection
con.Open();
4.Pass the Query
sql Command cmd = new sql Command("pass the query here",con);
5.Execute the Query
 cmd.executeNonQuery();
6.Close the Connnection
 con.Close();


Categories: ,

0 comments:

Post a Comment