0
Thanks

A few words of thanks would be greatly appreciated.

How to create database connectivity in asp.net

Asp.net provided functionality to connect to databases and access the data using SQL. In order to create database connectivity in asp.net, SQL server 2005 or MS Access 2007 can be used for the database. A small program code will be required to create the SQL connection to the database and perform database operations. Some knowledge of programming and SQL is essential to create database connectivity in asp.net. Namespace System.Data.SqlClient has to be used to make the connection to a database. The SQL connection is created through the SqlConnection API and operations on the database can be done through SqlCommand API.

Issue



I'm trying to create database connectivity in asp.net with the SQL server 2005 or MS Access 2007?
Can anybody help please?
Thanks in advance.

Solution

  • Step 1 : Add Namspace "using System.Data.SqlClient;"
  • Step 2 : Make SQL connection.


Write this code to create an SQL connection:

SqlConnection con = new SqlConnection("Server=You server name or comp name;Database=Yourdatabasename;Trusted_Connectopn=True");   
SqlCommand cmd = new SqlCommand("Write your sql query here eg. select * from Table name");  
con.Open();   
DataSet ds = new DataSet(cmd,con);   
SqlDataAdapter da = new SqlDataAdapter();   
da.Fill(ds);   
con.Close();

Note


Thanks to dEVELOPER for this tip on the forum.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team

Published by . Latest update on by Alan Oliver.

This document, titled "How to create database connectivity in asp.net," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).

0 Comments