I am buidling a web application using Visual Studio 2005 in VB.net. I have a web form that has several controls on it and I want to have a button that inserts the data entered in all the controls into a table in my SQL server db. My connection settings are stored in my web.config file. I cannot figure out how to refernce my saved connection setting in my web.config file and also, I am not sure that I have the code right for the other part of it. I am brand new to VS and this is my first web app. The class that I had signed up for to take was cancelled so I have been referencing a book and the Internet but have not had much luck.
I have attached my code so you can see what I have done. Any help would be greatly appreciated. Please let me know if I need to reference anything in my file as well.
WEB.CONFIG FILE CODE:
<add name="CMSConnectionString" connectionString="Data Source=AUSSQL;Initial Catalog=CMS;User ID=timecard;Password=***"
WEB FORM CODE:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oConn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("CMSConnectionString"))
Dim cmd As New System.Data.SqlClient.SqlCommand()
cmd.Connection = oConn
cmd.CommandText = "INSERT into Timecard(INEENO,INDTWE,INWKNO,INDYWK, INJBNO, INGLAN, INJCDI, INRGHR, INOVHR, INOTHR, INOTTY) values('" & EmplID1.Text & "','" & DatePicker1.DateValue & "','" & DD_DayofWeek.Text & "','" & jobno.Text & "','" & GLAcct.Text & "','" & DD_CostCode.Text & "','" & RegHrs.Text & "','" & OTHrs.Text & "','" & OthHrs.Text & "','" & DD_OthHourType.Text & "')"