Hoe can i connect the table into the c# application?

Answers were Sorted based on User's Feedback



Hoe can i connect the table into the c# application?..

Answer / umesh shrivastava

if we are using web application
1-open web.config file
<ConnectionString>
<add name="connect" connectionstring="Data Source=
,IntialCatalog= " Username= ,Password=
;providerName="System.Data.SqlClient"
</ConnectionString>
2-write namespace at the top in .cs file System.Data.SqlClient;
2-now write this code to button click event
String
ss=ConfigurationManager.ConnectionString["connect"].ConnectionString;
Sqlconnection con=new SqlConnection(ss);
con.open();
SqlCommand cmd=new SqlCommand("select * from emp",con);
SqlDataReader r=cmd.ExecuteReader();
con.close();

Is This Answer Correct ?    2 Yes 0 No

Hoe can i connect the table into the c# application?..

Answer / gaurav

by writing the connection string on the click event of the
button. by connection string i mean it's the ado.net
structure.firstly you have to include the namespace- using
system.data.sqlclient;
now on the click event of the button( eg u have taken a
sumbit button ) you will be writting- sqlconnenection con=
new sqlconnection........then u'll use
datacommand,dataset,string,databind,gridview.
u can also use read for getting the errors in a specified
manner.for this u will be using try and the catch then your
connection string code and then u'll use the finally
function and then close().

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Sharp Interview Questions

What are cshtml files?

0 Answers  


What is xaml file in c#?

0 Answers  


Is vs as c#?

0 Answers  


What are delegates?

0 Answers   TCS,


Do we get an error while executing the “finally” block in c#?

0 Answers  






What is constructor overloading in c#?

0 Answers  


What are delegates in C#?

0 Answers   Winsol Solutions,


Can we have 2 main methods in c#?

0 Answers  


What is uint c#?

0 Answers  


How to handle exceptions that are raised in a component?

0 Answers   Alcatel-Lucent,


What?s the difference between an interface and abstract class?

6 Answers   Mind Tree, Siebel,


What?s a multicast delegate?

3 Answers  


Categories