Hey guys,
Im really new at vb.net and i have a huge project on it.Somehow, ive managed to complete 90% of it but im stuck at the last 10%.This is a system basically set up for GPs.Medical Centre.The system has 3 users, patient doctor and admin.
The admin are allowed to book an appointment for the patients.Thts where im stuck at. The admin are supposed to get the patient name, doctor name, item number(consultation type,wether its a standard or a brief), booking date, booking start time, and end time.

The problem im having is, that when the admin is supposed to book an appointment, the system is supposed to make sure no double bookings are made. i.e a doctor is not booked for different patients at the same time and date. Ive tried the double bookings and i think it works. The problem is with the insertion. Somehow the data is inserted TWICE into the database and i cant figure out why. the double booking kind of works, because it does display the error that it can not be booked, but since the insert statement is executed first, it still does insert,but twice. I really need to get rid of the double insertion.Please HELP!:(

P.s. The code is Below.

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class Admin_Appointment
    Inherits System.Web.UI.Page


    Protected Sub Insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Insert.Click
        'Connection String'
        Dim connectionString As String = WebConfigurationManager.ConnectionStrings("projectConnectionString").ConnectionString
        Dim con As New SqlConnection(connectionString)

        'Sql for the select statement for comparision'

        Dim cmd As New SqlCommand("SELECT consultation_ID,doctor_ID,bookingdate,bookingtime,endtime FROM consultationTable", con)
        'Opening the connection'
        cmd.Parameters.AddWithValue("@doctor_ID", doctor_ID.Text)
        cmd.Parameters.AddWithValue("@bookingtime", bookingtime.Text)
        cmd.Parameters.AddWithValue("@endtime", endtime.Text)
        cmd.Parameters.AddWithValue("@bookingdate", bookingdate.Text)

        Using con
            con.Open()
            'Statement for Inserting the Values'
            Dim cmd2 As New SqlCommand("INSERT consultationTable (patient_ID,doctor_ID,bookingdate,bookingtime,endtime,item_no ) values ( @patient_ID, @doctor_ID, @bookingdate, @bookingtime, @endtime, @item_no )", con)
            Dim paramstring As String = doctor_ID.SelectedValue
            Dim anotherstring As String = patient_ID.SelectedValue
            cmd2.Parameters.AddWithValue("@doctor_ID", paramstring)
            cmd2.Parameters.AddWithValue("@patient_ID", anotherstring)
            cmd2.Parameters.AddWithValue("@bookingdate", bookingdate.Text)
            cmd2.Parameters.AddWithValue("@bookingtime", bookingtime.Text)
            cmd2.Parameters.AddWithValue("@endtime", endtime.Text)
            cmd2.Parameters.AddWithValue("@item_no", itemlist.Text)

            'Executing the Insert'
            Dim rowCount As Integer = cmd2.ExecuteNonQuery()
            'Execute the Select statement'
            Dim result As Object = cmd.ExecuteScalar()

            If Not IsNothing(result) Then

                If rowCount > 0 Then
                    lblResult.Text = "Booking Has Been Made"
                    'Make a new booking'
                ElseIf rowCount <= 0 Then
                    lblResult.Text = "Booking Could Not Be Made"
                Else
                    lblResult.Text = "Sorry a booking has already been made at that time."
                End If
            End If


        End Using

    End Sub
End Class

Thats the V.B code.Ive never coded in VB before.This is my first time so it may look a bit messed up.One thing i would like to understand in simple words is what does the AddWidthValue do?I tried looking it up but it was written to complicated for me to understand. Thanks.

<%@ Page Title="Appointment" Language="VB" MasterPageFile="Admin.master" AutoEventWireup="false"
    CodeFile="Appointment.aspx.vb" Inherits="Admin_Appointment" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

<form id="appointment">
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:projectConnectionString %>"
        SelectCommand="SELECT [patient_ID], firstname + ' ' + lastname AS name FROM [Patient_table]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:projectConnectionString %>"
        SelectCommand="SELECT [doctor_ID], firstname + ' ' + lastname AS name2 FROM [Doctor_table]">
    </asp:SqlDataSource>

            Patient Name:
            <asp:DropDownList ID="patient_ID" runat="server" DataSourceID="SqlDataSource2"
                DataTextField="name" DataValueField="patient_ID" />
            <br />
                
            Doctor Name:
            <asp:DropDownList ID="doctor_ID" runat="server" DataSourceID="SqlDataSource3"
                DataTextField="name2" DataValueField="doctor_ID" />
            <br />

<br />
Item Number:
             <asp:RadioButtonList ID="itemlist" runat="server">
                    <asp:ListItem Text="3 (Consult Brief)" Value="52"/>
                    <asp:ListItem Text="23 (Consult Standard)" Value="53" />         
                </asp:RadioButtonList>

<br />
Booking Date:
<asp:TextBox ID="bookingdate" runat="server"></asp:TextBox>  
<br />
Start Time:
<asp:TextBox ID="bookingtime" runat="server"></asp:TextBox>
<br />
End Time:

<asp:TextBox ID="endtime" runat="server"></asp:TextBox>

<br />


<asp:Button ID="Insert" Text="Insert" runat="server" OnClick="Insert_Click"/>
  
    <asp:Label
        id="lblResult"
        Runat="server" />  
</form>



 </asp:Content>

Thats the form code. The two sql datasources are basically used to get the doctor and patient names from the tables through the foriegn keys (patient id and doctor id) in the consultation Table.

Remove this -

Dim result As Object = cmd.ExecuteScalar()

statement.

Remove this -

Dim result As Object = cmd.ExecuteScalar()

statement.

I removed that and the select statement and everything related to that.I only left the insert queries and statments,but yet it still gives me the same result.The data is inserted twice again:S

.....


'Sql for the select statement for comparision'

Dim cmd As New SqlCommand("SELECT consultation_ID FROM consultationTable where ,doctor_ID=@doctor_ID and bookingdate=@bookingdate and bookingtime=@bookigtime and endtime=@endtime", con)


cmd.Parameters.AddWithValue("@doctor_ID", doctor_ID.Text)
cmd.Parameters.AddWithValue("@bookingtime", bookingtime.Text)
cmd.Parameters.AddWithValue("@endtime", endtime.Text)
cmd.Parameters.AddWithValue("@bookingdate", bookingdate.Text)


con.Open()
Dim result As Object = cmd.ExecuteScalar()

If Not IsNothing(result) Then
            lblResult.Text = "Sorry a booking has already been made at that time."
else
            Dim cmd2 As New SqlCommand("INSERT consultationTable (patient_ID,doctor_ID,bookingdate,bookingtime,endtime,item_no ) values ( @patient_ID, @doctor_ID, @bookingdate, @bookingtime, @endtime, @item_no )", con)
            Dim paramstring As String = doctor_ID.SelectedValue
            Dim anotherstring As String = patient_ID.SelectedValue
            cmd2.Parameters.AddWithValue("@doctor_ID", paramstring)
            cmd2.Parameters.AddWithValue("@patient_ID", anotherstring)
            cmd2.Parameters.AddWithValue("@bookingdate", bookingdate.Text)
            cmd2.Parameters.AddWithValue("@bookingtime", bookingtime.Text)
            cmd2.Parameters.AddWithValue("@endtime", endtime.Text)
            cmd2.Parameters.AddWithValue("@item_no", itemlist.Text)

            'Executing the Insert'
            Dim rowCount As Integer = cmd2.ExecuteNonQuery()
           
            lblResult.Text = "Booking Has Been Made"
        
End If
......

hi all i wont someone to help me that i make system but am stop that i wont a code to prodram butoon to upload picture but i nee form style and the code please help me ... thnks..!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.