how to connect database in c#

>how to connect database in c#

You need to create an instance Connection class. This instance then uses connect information (connectionString) - database servername, userid, password and database name to connect.

Create a new instance for the database.Here is an example

SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Data Source=(yourserver)\\SQLEXPRESS;Initial Catalog=(your databasename);Integrated Security=True;Pooling=False";
            cn.Open();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.