been trying to link a webfrom to a sqlexpress database witinin my asp.net booking system project but keep coming up blank, i have tried alot of different ways but this one seems to be the easiest and im still having major problems. it needs to be connected
by sunday.
The "btnsubmit.click" isnt working and saying that it need to be have a withevents variable
Also "txtDateofBooking.text" and "txtTimeofBooking.text" are both showing with blue lines under them
and is "Partial Class" suppose to be the page im working from which is "Bookings". Ive started to confuse myself looking at alot of different code over the past week.
Partial Class Bookings
Inherits System.Web.UI.Page
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
End Sub
Public Sub CreateCommand(ByVal queryString As String, _
ByVal connectionString As String)
Dim myconn As SqlConnection
Dim cmd As SqlConnection
Dim sqlstring, [ActivityName], [DateofBooking], [TimeofBooking] As String
thank you for that coding it looks like it will work although it is still throwing up the following
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click ---BTNSUBMIT is throwing up (HANDLES CLAUSE REQUIRES A WITHEVENTS VARIABLE DEFINED IN THE CONTAING TYPE OR ONE OF ITS BASE TYPES)
Dim myconn As SqlConnection
Dim cmd As SqlConnection
Dim sqlstring, [ActivityName], [DateofBooking], [TimeofBooking] As String
[ActivityName] = ddlActivityName.SelectedValue.ToString
[DateofBooking] = txtDateofBooking.text ( NOT DECLARED)
[TimeofBooking] = txtTimeofBooking.text ( NOT DECLARED)
myconn = new SqlConnection("Provider=SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
myconn.Open()
sqlstring = "INSERT INTO Bookings (Activity Name, Time of Booking, Date of Booking)Values('" + [ActivityName] + "', '" + [DateofBooking] + "', '" + [TimeofBooking] + "') " '
Dim command As New SqlCommand(queryString, myconn) - in this line queryString -( NOT DECLARED)
command.Connection.Open()
command.ExecuteNonQuery()
myconn.Close()
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim myconn As SqlConnection
Dim cmd As SqlConnection
Dim sqlstring As String=""
Dim [ActivityName] As String = ddlActivityName.SelectedValue.ToString DIm [DateofBooking] As String = txtDateofBooking.Text Dim [TimeofBooking] As String = txtTimeofBooking.Text
myconn = new SqlConnection("Provider=SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
myconn.Open()
sqlstring = "INSERT INTO Bookings (Activity Name, Time of Booking, Date of Booking)Values('" + [ActivityName] + "', '" + [DateofBooking] + "', '" + [TimeofBooking] + "') " '
Dim command As New SqlCommand(queryString, myconn) - in this line queryString -( NOT DECLARED)
command.Connection.Open()
command.ExecuteNonQuery()
myconn.Close()
Dim [ActivityName] As String = ddlActivityName.SelectedValue.ToString DIm [DateofBooking] As String = txtDateofBooking.Text Dim [TimeofBooking] As String = txtTimeofBooking.Text
in this change u ask me to make the - txtTimeofBooking.Text - txtDateofBooking.Text- i added " " to either side for it to work in the string but its still not doing anything
jbeattie629
0 Points
26 Posts
submit button and declaring of a text box , Booking system need HELP ASAP
Apr 12, 2012 01:17 PM|LINK
been trying to link a webfrom to a sqlexpress database witinin my asp.net booking system project but keep coming up blank, i have tried alot of different ways but this one seems to be the easiest and im still having major problems. it needs to be connected by sunday.
The "btnsubmit.click" isnt working and saying that it need to be have a withevents variable
Also "txtDateofBooking.text" and "txtTimeofBooking.text" are both showing with blue lines under them
and is "Partial Class" suppose to be the page im working from which is "Bookings". Ive started to confuse myself looking at alot of different code over the past week.
Partial Class Bookings
Inherits System.Web.UI.Page
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
End Sub
Public Sub CreateCommand(ByVal queryString As String, _
ByVal connectionString As String)
Dim myconn As SqlConnection
Dim cmd As SqlConnection
Dim sqlstring, [ActivityName], [DateofBooking], [TimeofBooking] As String
[ActivityName] = ddlActivityName.SelectedValue.ToString
[DateofBooking] = txtDateofBooking.text
[TimeofBooking] = txtTimeofBooking.text
myconn = new SqlConnection("Provider=SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
myconn.Open()
sqlstring = "INSERT INTO Bookings (Activity Name, Time of Booking, Date of Booking)Values('" + [ActivityName] + "', '" + [DateofBooking] + "', '" + [TimeofBooking] + "') " '
Dim command As New SqlCommand(queryString, myconn)
command.Connection.Open()
command.ExecuteNonQuery()
myconn.Close()
End Sub
End Class
Shankar_ss
Participant
1270 Points
279 Posts
Re: submit button and declaring of a text box , Booking system need HELP ASAP
Apr 12, 2012 01:27 PM|LINK
In your buttonclick event, there is no code. You have to either write you code for saving to database in it or call someother function from there:
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
--- Here you have to include your code for execution on button click event.
End Sub
In the button & textbox, have you included runat="server". This is essential for code behind to automatically declare it.
Hope this helps.
Shankar
jbeattie629
0 Points
26 Posts
Re: submit button and declaring of a text box , Booking system need HELP ASAP
Apr 12, 2012 02:06 PM|LINK
sorry i dont understand what you mean by include my code for the execution on the button click event? do u have an example?
Shankar_ss
Participant
1270 Points
279 Posts
Re: submit button and declaring of a text box , Booking system need HELP ASAP
Apr 12, 2012 06:53 PM|LINK
I have taken your code from below and pasted in the btnsumbit.click event like this:
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim myconn As SqlConnection
Dim cmd As SqlConnection
Dim sqlstring, [ActivityName], [DateofBooking], [TimeofBooking] As String
[ActivityName] = ddlActivityName.SelectedValue.ToString
[DateofBooking] = txtDateofBooking.text
[TimeofBooking] = txtTimeofBooking.text
myconn = new SqlConnection("Provider=SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
myconn.Open()
sqlstring = "INSERT INTO Bookings (Activity Name, Time of Booking, Date of Booking)Values('" + [ActivityName] + "', '" + [DateofBooking] + "', '" + [TimeofBooking] + "') " '
Dim command As New SqlCommand(queryString, myconn)
command.Connection.Open()
command.ExecuteNonQuery()
myconn.Close()
End Sub
Please check if this works. If not, make alterations to your insert statement.
Shankar
jbeattie629
0 Points
26 Posts
Re: submit button and declaring of a text box , Booking system need HELP ASAP
Apr 12, 2012 08:53 PM|LINK
thank you for that coding it looks like it will work although it is still throwing up the following
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click ---BTNSUBMIT is throwing up (HANDLES CLAUSE REQUIRES A WITHEVENTS VARIABLE DEFINED IN THE CONTAING TYPE OR ONE OF ITS BASE TYPES)
Dim myconn As SqlConnection
Dim cmd As SqlConnection
Dim sqlstring, [ActivityName], [DateofBooking], [TimeofBooking] As String
[ActivityName] = ddlActivityName.SelectedValue.ToString
[DateofBooking] = txtDateofBooking.text ( NOT DECLARED)
[TimeofBooking] = txtTimeofBooking.text ( NOT DECLARED)
myconn = new SqlConnection("Provider=SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
myconn.Open()
sqlstring = "INSERT INTO Bookings (Activity Name, Time of Booking, Date of Booking)Values('" + [ActivityName] + "', '" + [DateofBooking] + "', '" + [TimeofBooking] + "') " '
Dim command As New SqlCommand(queryString, myconn) - in this line queryString -( NOT DECLARED)
command.Connection.Open()
command.ExecuteNonQuery()
myconn.Close()
End Sub
Shankar_ss
Participant
1270 Points
279 Posts
Re: submit button and declaring of a text box , Booking system need HELP ASAP
Apr 13, 2012 07:16 AM|LINK
Change Private Sub to Protected Sub.
Think it will solve the problem. Let me know after you try.
Shankar
jbeattie629
0 Points
26 Posts
Re: submit button and declaring of a text box , Booking system need HELP ASAP
Apr 13, 2012 09:02 AM|LINK
changing it to protected sub didnt change anything still throwing up problems with it saying a few bits of it are not declared.
sriramabi
Contributor
4351 Points
1277 Posts
Re: submit button and declaring of a text box , Booking system need HELP ASAP
Apr 13, 2012 09:10 AM|LINK
hi
change pls
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim myconn As SqlConnection
Dim cmd As SqlConnection
Dim sqlstring As String=""
Dim [ActivityName] As String = ddlActivityName.SelectedValue.ToString
DIm [DateofBooking] As String = txtDateofBooking.Text
Dim [TimeofBooking] As String = txtTimeofBooking.Text
myconn = new SqlConnection("Provider=SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
myconn.Open()
sqlstring = "INSERT INTO Bookings (Activity Name, Time of Booking, Date of Booking)Values('" + [ActivityName] + "', '" + [DateofBooking] + "', '" + [TimeofBooking] + "') " '
Dim command As New SqlCommand(queryString, myconn) - in this line queryString -( NOT DECLARED)
command.Connection.Open()
command.ExecuteNonQuery()
myconn.Close()
End Sub
thank u
sriramabi
Contributor
4351 Points
1277 Posts
Re: submit button and declaring of a text box , Booking system need HELP ASAP
Apr 13, 2012 09:16 AM|LINK
or change this line only
Dim sqlstring As String=""
Dim [ActivityName] As String=""
Dim [DateofBooking] As String=""
Dim [TimeofBooking] As String=""
//then u r code below................
thank u
jbeattie629
0 Points
26 Posts
Re: submit button and declaring of a text box , Booking system need HELP ASAP
Apr 13, 2012 09:40 AM|LINK
Dim sqlstring As String
Dim [ActivityName] As String = ddlActivityName.SelectedValue.ToString
DIm [DateofBooking] As String = txtDateofBooking.Text
Dim [TimeofBooking] As String = txtTimeofBooking.Text
in this change u ask me to make the - txtTimeofBooking.Text - txtDateofBooking.Text- i added " " to either side for it to work in the string but its still not doing anything
========================================================