Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What are the steps in connecting to database?

Answer Posted / sireesha

C#:
System.Data.SqlClient;
In the method {}...
Step 1: Create a connection:
SqlConnection con = new SqlConnection();
Con.ConnectionString = “DataSource =Server Name;
Initial Catalog = Database Name; Integrated Security=True”;
Step 2: Create a Command:
SqlCommand cmd = new SqlCommangd();
Step 3: Bind the Command to Connection:
cmd.Connection = con;
Step 4: Initialise the Command with SQL Statement to execute
EX:-
String Name = txtName.Text;
decimal Salary = decimal.parse(txtsalary.Text);
cmd.CommandText = "insert into Emp
(EmpName,EmpSalary) Value(' "+name+" ',"+salary")";
Step 5: Open the Connection
con.Open();
Step 6: Execute the Command
Like we have different execute command statements
like ExecuteNonQuery(),ExecuteScalar(),ExecuteReader(). Use
as per the requirement of data.
Step 7: Close the connection
con.Close();

Is This Answer Correct ?    8 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the steps you will take to improve performance?

849


How do you connect to sql server database without using sqlclient?

1058


What is Data Provider?

1002


What are the ado.net connection pooling parameters?

919


Which one of the following objects is a high-level abstraction of the connection and command objects in ado.net?

1028


What is data access pattern?

879


Which method is used to sort the data in ADO.Net?

1927


What is connection in ado.net?

897


How to read data with the sqldatareader ?

928


What is the difference between OLEDB Provider and SqlClient?

949


Define data adapter?

900


how we can fire event in databound coulm in datagfrid withot using button?

917


What are the data providers used in ado.net

981


Is ado.net dead?

958


What is ado.net and its features?

932