Hello
I am new to web design and I am trying to add a guest book facility to my website. However I keep on getting compliling errors in Visual Web Express when trying to run the page. I have a sqlexpress DB setup and I can get manually entered data to display in a data grid fine by using a SQLDataSource object. However I cannot get the form with the Name, Location and Comments text boxes to post into the Database.mb guestbook table. This is my current code below and I am using a command button to try and submit this. Any help extremley welcomed.
Thanks
ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click
If IsPostBack Then
Dim Name AsString = TextBox1.Text
Dim Location AsString = TextBox2.Text
Dim Comments AsString = TextBox3.Text
Dim conn As OleDbConnection = New OleDbConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
Dim qry AsString
Dim cmd As OleDbCommand
qry = "Insert into guestbook (name,location,comment) VALUES ('" & Name & "',''" & Location & "','" & Comments & "'" & ")"
cmd = New OleDbCommand(qry, conn)
Try
conn.Open()
cmd.ExecuteNonQuery()
Catch e As Exception
Throw e
Finally
If conn.State = ConnectionState.Open Then
conn.Close()
EndIf
EndTry
EndIf
EndSub
I am new to web design and I am trying to add a guest book facility to my website. However I keep on getting compliling errors in Visual Web Express when trying to run the page. I have a sqlexpress DB setup and I can get manually entered data to display in a data grid fine by using a SQLDataSource object. However I cannot get the form with the Name, Location and Comments text boxes to post into the Database.mb guestbook table. This is my current code below and I am using a command button to try and submit this. Any help extremley welcomed.
Thanks
ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Button1.Click
If IsPostBack Then
Dim Name AsString = TextBox1.Text
Dim Location AsString = TextBox2.Text
Dim Comments AsString = TextBox3.Text
Dim conn As OleDbConnection = New OleDbConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
Dim qry AsString
Dim cmd As OleDbCommand
qry = "Insert into guestbook (name,location,comment) VALUES ('" & Name & "',''" & Location & "','" & Comments & "'" & ")"
cmd = New OleDbCommand(qry, conn)
Try
conn.Open()
cmd.ExecuteNonQuery()
Catch e As Exception
Throw e
Finally
If conn.State = ConnectionState.Open Then
conn.Close()
EndIf
EndTry
EndIf
EndSub