Database connectivity in


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Database connectivity in

  1. 1. 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 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 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 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 @ 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 @ Like us @ Subscribe to us @ Become a follower @ Connect to us @ Give a feedback @ Thanks in advance | |
  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: Contact Us