STEPS WHILE WORKING WITH SQL SERVER  :

-> Step 1: Import the library at the top.

->Step 2: Construct the “Connection” Class object.

-> Step 3: Assign the Connection String.

If u are using Windows authentication in Sql Server, then the  Connection string will be like this

If you are using Sql Server authentication for Sql Server then the connection string is like this.

-> Step 4: Open the connection:

-> Step 5: Construct the  “Command” class object:

-> Step 6: Assign the SQL Statement, which is to be executed:

-> Step 7: Assign the reference of connection object, to which the command is to be executed.

->Step 8: Execute the Command and receive the number of rows effected.

In the Above Statement we have to call the ExecuteNonQuery() method if the command Text Contains the “insert/update/delete” command.
If the Command is “Select” command, then we have to call the  ExecuteQuery( ) method instead of ExecuteNonQuery( )

-> Step 9: Close the Connection:

 

Leave a Reply

Your email address will not be published. Required fields are marked *