Database connectivity in asp.net
Upcoming SlideShare
Loading in...5
×
 
  • 105 views

 

Statistics

Views

Total Views
105
Views on SlideShare
105
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Database connectivity in asp.net Database connectivity in asp.net Presentation Transcript

  • Meenusoman meenusoman99@gmail.com www.facebook.com/Meenusoman twitter.com/meenusoman in.linkedin.com/in/Meenusoman Phonenumber
  • Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • How to connect an asp.net application with Database • ConnectionString:- The database connection information is stored in the web.configfile as a ConnectionString tag. •Web.configis a xml file which is used to store application wide settings and constants
  • How to connect an asp.net application with Database •The ConnectionString has two main attributes Name:–this holds a name for the connectionstring with which a particular connectionstringis identified, useful when using multiple databases ConnectionString–this holds the actual connection data
  • Getting the connection information from within the application • The connection string added in the web.configcan be obtained from anywhere within the application using the following line of code String constring=configurationManager.ConnectionString["connection"].con nectionString; ConnectionStringname as given in the web.config
  • Cont…. • For connecting to the database from anasp.net application we use the following inbuilt classes of the .netframework -sqlCommandobject -sqlConnectionobject -sqlDataReader/ sqlDataAdapterobject
  • Creating and initializing the sqlCommandobject • The following lines of code creates an sqlCommandobject and initializes it string conString = ConfigurationManager.ConnectionStrings["connection"].ConnectionStri ng; SqlConnection conn = new SqlConnection(conString); string query="insert into tbl_user values('"+txtname.Text+"','"+txtpassword.Text+"','"+txtaddress.Text+"')"; SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close();
  • Sytax for Data Retrieve string conString = ConfigurationManager.ConnectionStrings["connection"].Conn ectionString; SqlConnection con = new SqlConnection(conString); string query = "select * from tbl_user where vchr_username='" +txtlogname.Text+ "' and vchr_password='" + txtlogpass.Text + "'"; SqlCommand cmd = new SqlCommand(query, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet();
  • END
  • Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
  • Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  • Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us