Sunday, 16 June 2013

How to make connection with DataBase in C#



The below explanation, shows, the  way by which we can make the connection with  the database

Example
               suppose a table" Employee"

Make the connection with database in the web.config file

the below connection in case the database is  Sql server Authentication 

<connectionStrings>
    <add name="MyString" connectionString="DataSouce = LocalHost; DataBase=DBName; UID=sa; Password = PWDName;"/>
  </connectionStrings>

2: For Windows Authentication

<ConnectionStrings>
   <add name="MyString" ConnectionString="server= Sqlservername; database=DataBaseName;  Integrated Security = "True";>
</ConnectionStrings>

Now the connection has been established  with the database , and required to read data from
the database

The Below  should be written in code behind , is used to play with  the data;
string str = ConfigurationManager.ConnectionString["MyString"].connectionString;

0 comments:

Post a Comment