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
What are the steps you will take to improve performance?
How do you connect to sql server database without using sqlclient?
What is Data Provider?
What are the ado.net connection pooling parameters?
Which one of the following objects is a high-level abstraction of the connection and command objects in ado.net?
What is data access pattern?
Which method is used to sort the data in ADO.Net?
What is connection in ado.net?
How to read data with the sqldatareader ?
What is the difference between OLEDB Provider and SqlClient?
Define data adapter?
how we can fire event in databound coulm in datagfrid withot using button?
What are the data providers used in ado.net
Is ado.net dead?
What is ado.net and its features?