Hi, i am now doing a Car rental system web project. Well the interface is very similiar to http://www.avis.com.sg/, which i have extra modelname dropdownlist.
Here is my code.Label 7 is just a Label to indicate Booking_ID number. MY Table consist of Booking_ID,Star tDate,EndDate,M odelname,branch _ID,customer_ID respectively.
I just couldnt insert the data into my SQL database even though i have insert the datas in all my of the dropdownlist and click submit. The Data is still not inserted with no error encountered. I suspect is the date problem.
Please assit.
Here is my code.Label 7 is just a Label to indicate Booking_ID number. MY Table consist of Booking_ID,Star tDate,EndDate,M odelname,branch _ID,customer_ID respectively.
I just couldnt insert the data into my SQL database even though i have insert the datas in all my of the dropdownlist and click submit. The Data is still not inserted with no error encountered. I suspect is the date problem.
Please assit.
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
Dim strcon As String = "Data Source=BISHAN\MICROSOFTSQL;Integrated Security=True;Pooling=False;Initial Catalog='AbelProject'"
Dim con As SqlConnection = New SqlConnection(strcon)
Dim cmd As New SqlCommand
Dim cmd2 As New SqlCommand
Dim cmd3 As New SqlCommand
con.Open()
cmd3.Connection = con
Label5.Text = cmd3.ExecuteScalar()
If Not Page.IsPostBack Then
FillCarmodelList()
FillbranchList()
FillHourlist()
FillminuteList()
FilldayList()
Fillmonthlist()
End If
Dim i As Integer
cmd.CommandText = "select count(*) from Rent_Record "
cmd.Connection = con
i = cmd.ExecuteScalar()
Label7.Text = i + 1
'If i <= 0 Then
'cmd.CommandText() = "Insert into Rent_Record values"
Dim insertsql As String
insertsql = "INTO Rent_Record ('Booking_ID')"
insertsql &= "values('" + Label7.Text + "')"
'ElseIf i > 0 Then
'Dim insertsql As String
'insertsql = "INTO Rent_Record ("
'insertsql &= "Booking_ID)"
'insertsql &= "values('" + Label7.Text + "')"
'insertsql &= "values('"
'insertsql &= "i + 1 '")
'End If
con.Close()
con.Dispose()
End Sub
Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
Dim strcon As String = "Data Source=BISHAN\MICROSOFTSQL;Integrated Security=True;Pooling=False;Initial Catalog='AbelProject'"
Dim con As SqlConnection = New SqlConnection(strcon)
Dim startdate As DateTime
Dim enddate As DateTime
'Create SQL command object
Dim cmd As New SqlCommand
con = New SqlConnection(strcon)
'connect command to connection
cmd.Connection = con
startdate.Hour.Equals(MonthList1.SelectedItem.Text)
'startdate.Hour.Equals(MonthList1.SelectedItem.Text)
'startdate.Day.Equals(DayList1.SelectedItem.Text)
'startdate.Minute.Equals(MinuteList1.SelectedItem.Text)
enddate.Hour.Equals(MonthList2.SelectedItem.Text)
enddate.Day.Equals(Daylist2.SelectedItem.Text)
enddate.Minute.Equals(MinuteList2.SelectedItem.Text)
con.Open()
' cmd.CommandText() = "Insert into Customer values ('" + _
'Label7.Text(+"','" + _
'startdate.Date + "','" + _
'enddate.Date + "','" + _
'CarModelList.SelectedItem.Text + "','" + _
'BranchList.SelectedItem.Text + "','" + _
'Session("customerID") + "')")
cmd.CommandText() = "update rent_record set startDate = '" + startdate.Date + _
"', enddate = '" + enddate.Date + _
"', modelname = '" + CarModelList.SelectedItem.Text + _
"',Branch_ID = '" + BranchList.SelectedItem.Text + _
"',Customer_ID= '" + Session("customerID") + _
"'" + _
" Where Booking_ID = '" + Label7.Text + "'"
cmd.ExecuteNonQuery()
con.Close()
con.Dispose()
Response.Redirect("BookingConfirm.aspx")
End Sub
Comment