Database connectivity in asp.net

444 views
341 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
444
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Database connectivity in asp.net

  1. 1. Meenusoman meenusoman99@gmail.com www.facebook.com/Meenusoman twitter.com/meenusoman in.linkedin.com/in/Meenusoman Phonenumber
  2. 2. 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
  3. 3. 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
  4. 4. 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
  5. 5. 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
  6. 6. Cont…. • For connecting to the database from anasp.net application we use the following inbuilt classes of the .netframework -sqlCommandobject -sqlConnectionobject -sqlDataReader/ sqlDataAdapterobject
  7. 7. 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();
  8. 8. 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();
  9. 9. END
  10. 10. 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.
  11. 11. 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
  12. 12. 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

×