• 0

[ASP.NET VB] Inserts into database twice


Question

hey,

im helping out a friend doing some ASP.NET VB work, but i cant figure out why its inserting into the database twice, im hoping somewhere here can :D

Imports System.Data.OleDb

Partial Class admin
    Inherits System.Web.UI.Page

    Protected Sub book_appointment(ByVal sender As Object, ByVal e As System.EventArgs) Handles book.Click
        Dim myConnection As OleDbConnection
        Dim myCommand As OleDbCommand
        Dim strSQL As String

        Dim book_date As String
        Dim book_time As String
        Dim service As String
        Dim username As String

        book_date = bookdate.Text
        book_time = booktime.Text
        service = bookservice.Text
        username = Request.Cookies("username").Value.ToString()

        strSQL = "INSERT INTO booking ([username], [date], [time], [service]) VALUES ('" _
        & username & "', '" _
        & book_date & "', '" _
        & book_time & "', '" _
        & service & "')"

        myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
       & "Data Source=" & Server.MapPath("database/Admin_Database.mdb") & ";")


        myCommand = New OleDbCommand(strSQL, myConnection)
        Try
            myConnection.Open()
            myCommand.ExecuteScalar()
            myConnection.Close()
        Catch ex As Exception
            output.Text = ex.ToString()
        End Try
        output.Text = "Appointment Booked!"
    End Sub
End Class

Thanks in advance

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

What version of ASP.NET are you using? Isn't an OleDbConnection/OleDbCommand a bit... primitive? There must be a more object-oriented way to interact with an Access database. Have you read this? Or looked into LINQ?

Link to comment
Share on other sites

  • 0

What version of ASP.NET are you using? Isn't an OleDbConnection/OleDbCommand a bit... primitive? There must be a more object-oriented way to interact with an Access database. Have you read this? Or looked into LINQ?

thanks for the reply,

this site wont be going online or anything, so i just need a quick and simple solution.

i am using asp.net 3.5

everything else on the site works, apart from this :( and i cant figure out why.

any help is appreciated.

Thanks

Link to comment
Share on other sites

  • 0

Have you stepped through with the Debugger to see if the method is only being called once?

thanks for the reply.

i have not tried this, mainly because i do no know how :(

im using visual web developer 2008 express, how do i step through it with the debugger?

Thanks

Link to comment
Share on other sites

  • 0

just figured out how to step through, its going through the method twice, but i dont know why.

this is how the method is called

<p><asp:Button ID="book" runat="server" OnClick="book_appointment" Text="Book Appointment" /></p>

thanks in advance

Link to comment
Share on other sites

  • 0

have you tried removing the "Handles book.Click" part of the code?

i havent, but i will try it and get back to you.

thanks for the suggestion

Link to comment
Share on other sites

  • 0

It does look like the event handler is being assigned twice, once in the source view:

onclick="book_appointment"

and also in code:

Handles book.Click

Pick one or the other ;)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.