Database connectivity in
Upcoming SlideShare
Loading in...5




Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



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.

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

Database connectivity in Database connectivity in Presentation Transcript

  • 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 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 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 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 @ 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 @ Like us @ Subscribe to us @ Become a follower @ Connect to us @ Give a feedback @ Thanks in advance | |
  • 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