What are the steps in connecting to database?

Answers were Sorted based on User's Feedback



What are the steps in connecting to database?..

Answer / chaitanya.k

1. U need to declare name space according to which database
u need to connect.

2. U can declare connection string in two ways.

1. U can declare in web.config in appsettings.
2. U can delare directly in code behind or in inline code

These can delared by using connection string.

3. Then u can do the operations by open the connection.
4. After complete all ur transcations u need to close the
database.

Is This Answer Correct ?    10 Yes 3 No

What are the steps in connecting to database?..

Answer / 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

What are the steps in connecting to database?..

Answer / sanket pandit

An alternate, and preferred way, to using the DriverManager class is to use a DataSource object.

This is for SQ L Ans.
1. The data source is registered on the server side, which stores connection information, like: host, port, sid, credentials (optional), driver to use, etc.

2. The application gets a handle on the data source through a JNDI lookup.

3. The DataSource object is a connection factory and you can invoke .getConnection()

One of the reasons it is preferred over the DriverManager is because it is more flexible. The connection in

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More ADO.NET Interview Questions

how do u connect ado.net to sql server

1 Answers   Microsystems,


What is azure ado?

1 Answers  


What is the provider being used to access oracle database?

0 Answers  


What is the use of connection object in ado.net?

0 Answers   TryTechnicals Pvt Ltd,


What is a control toolbox?

0 Answers  






Explain the namespaces in which .net has the data functionality class.

0 Answers  


What is ado.net tutorial?

0 Answers  


What is main five diffrent between Connected And Disconnected environment

15 Answers   HCL, Satyam, US India, Wipro,


Define Execute Reader?

0 Answers  


What are the attirbutes of DataSet?

5 Answers   IBM,


how would i implement dropdownlist in gridview using c#

2 Answers  


suppose we using gridview contrl,with sqldatasource.in that for birth date how can we take validation contrl for dd/mm/yy formator how we assign regular expression for same

9 Answers   TCS,


Categories