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 is ole2 format?
What is ado connection?
What are the rules to implement connection pooling?
Is bulk insert faster than insert?
What is ado.net architecture?
What is the purpose of using adodb?
What are the steps to connect to a database?
What is the advantage of ado.net?
Which method is used by command class to execute SQL statements that return single value?
What is the DataTableCollection?
Difference between sqlcommand and sqlcommandbuilder?
What are the difference between readonly vs. Const?
Command objects uses, purposes and their methods.
What is different between sqlcommand object and command behavior object?
Explain all the classes those are used for database connections between sql server and asp.net?