Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to make Database connection in ASP.NET

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-03-2009
Member
 
Join Date: Feb 2009
Posts: 62
How to make Database connection in ASP.NET
  

Hello Friends,

Can anyone suggest me the procedure about how to make Database connection in ASP.Net, I wanted to apply it into my project so please help.


Thanks for your help

Reply With Quote
  #2  
Old 05-03-2009
Member
 
Join Date: Dec 2008
Posts: 202
Re: How to make Database connection in ASP.NET

Hi,
please add the follwoing code in you aspx.cs page.

Step 1 : Add Namspace "using System.Data.SqlClient;"

Step 2 : Make Sql connection.

Write this code to create 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();

i hope this should work
Reply With Quote
  #3  
Old 05-03-2009
Member
 
Join Date: Dec 2008
Posts: 161
Re: How to make Database connection in ASP.NET

1: Open visual studio 2005 and from FILE select NEW-> WebSite, then from pop-menu select asp.net
website (Note: Language must be C#) , then press OK.

2: Now create three textboxes from the toolbox , to remove ambiguity I am using default name for that textboxes and that should be textbox1,textbox2 & textbox3. And also drag & drop the button to the asp.net application.

3: Meanwhile, Open SQL SERVER Management studio 2005 and open adventureworks(or you can create your own database by the Sql command CREATE DATABASE database_name), but here I am using AdventureWorks database.

4: Then create table by clicking right mouse button and form three column, Name them according to your requirement , for your information only I used EID,name,Address. And click save button, then you’ll get a pop up menu where you have to enter the Table Name, for this example I used students.

5: Now Come Back to Visual studio Application and write the following code in the button_click event.

Code:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = “Connection string(See Below for this — )COPY PASTE  HERE“;

myConn.Open();
string strqry = “Insert into students values (” + TextBox1.Text +
“,’” + TextBox2.Text + “‘,’” + TextBox3.Text + “‘)”;

SqlCommand myCom = new SqlCommand(strqry, myConn);
int numrow = myCom.ExecuteNonQuery();
myConn.Close();

}
Reply With Quote
  #4  
Old 25-09-2011
Member
 
Join Date: Sep 2011
Posts: 1
Re: How to make Database connection in ASP.NET

A simple database program in VB.NET and C# , hope this will help you.
Reply With Quote
  #5  
Old 16-11-2011
Member
 
Join Date: Nov 2011
Posts: 1
Re: How to make Database connection in ASP.NET and where we have to choose that path

how to connect microsoft access database to asp.net and where we have to choose that path
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to make Database connection in ASP.NET"
Thread Thread Starter Forum Replies Last Post
VPN Error 5 : No hostname exists for this connection entry. Unable to make VPN connection Xmen Networking & Security 9 14-05-2012 06:05 PM
How to make database for xcode Farren Software Development 4 27-03-2012 11:17 AM
CAR MAKE & MODEL database karv Software Development 2 07-10-2011 02:19 PM
Make PAYPAL payment and save data on database Eshita The Techie Software Development 4 18-01-2011 02:52 PM
How to make the Database connection in PHP AK_Chopra Software Development 3 05-09-2009 09:35 AM


All times are GMT +5.5. The time now is 10:25 PM.