Monday, April 23, 2012

How to connecting to SQLserver from application

Title: How to create connection string in using

If you want to connect with SQLServer from application ,you can either use the OLEDB class as well as SQL Client classes.While connecting with OLEDB Connection to mention the target data source we specify the name of the provider which has be to be used.But when you use SQL connection or Oracle connection classes the connection string does not require the provider name to be specified.Here i will show an example to get the data from database using connection object

Using system.Data.SqlClient
SqlConnection cn;
SqlCOmmand cmd;
SqlDataReader dr;
under page load
cn=New SqlConnection("user id=sa;password=123;");
cmd=New SqlCommand("select*from students",cn);;

No comments: