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

Explain sqlconnection object?

1 Answers  


Which is faster datareader or dataadapter?

1 Answers  


What is commandbuilder in ado.net?

1 Answers  


What is a database provider?

2 Answers   BioSys,


What do you know about ado.net's objects?

1 Answers  


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

1 Answers  


What is sqldatasource?

1 Answers  


What is the difference between oledbreader and datasetwhile connecting?

1 Answers  


Is it possible to load multiple tables in a Dataset?

1 Answers  


Which is faster sqldataadapter and sqldatareader?

1 Answers  


What is DataRowCollection?

1 Answers  


How will you differentiate between ADO (ActiveX Data Object) and RDO (Remote Data Objects)?

1 Answers   CGI,


Categories