Monday, August 4, 2014

There are 6 easy steps to connect with database in and using

    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 or 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
4.Pass the Query
sql Command cmd = new sql Command("pass the query here",con);
5.Execute the Query
6.Close the Connnection

Categories: ,


Post a Comment