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

// Declare Namespace as ur Lang...
In c#

Using System.Data.SqlClient;

//connection

SqlConnection con = new
SqlConnection("server=localhost;database=Grid_Db;uid=sa;pwd=;");

con.Open();

SqlCommand cmd = new SqlCommand("select * from Gtid_Tbl",con);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds);

GridView1.DataSource = ds;
GridView1.DataBind();

Is This Answer Correct ?    6 Yes 1 No

What are the steps in connecting to database ?..

Answer / khalid

// Declare Namespace as ur Lang...
In c#

Using System.Data.SqlClient;

//connection
//If u provide uname & passwd to ur Database then this state //is true
SqlConnection con = new
SqlConnection("server=localhost;database=urDB_Name;uid=sa;pwd=;");
//else
SqlConnection con = new
SqlConnection("server=localhost;database=urDB_Name;");

con.Open();
if(con!=null)
msgbox("Connection sucessfully Done!");
else
msgbox("Sorry!Connection sucessfully is not Done!");

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More ADO.NET Interview Questions

What are all the commands used with Data Adapter?

0 Answers  


What is sqldatareader?

0 Answers  


Is ADO.NET derived from COM? true /false

2 Answers   Infosys,


What is the use of SqlCommand object?

0 Answers  


How is entity framework different from ado.net?

0 Answers  






How can we perform transactions in .net?

0 Answers  


How do we invoke queries from the application

2 Answers  


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

0 Answers  


What are the differences between OLEDB and SQLClient Providers?

0 Answers  


What is the provider and namespaces being used to access oracle database?

5 Answers   E2E, Microsoft,


What are the major difference between classic ADO and ADO.NET?

0 Answers  


What is an orm, and why would you use one instead of plain old ado.net?

0 Answers  


Categories