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,StartDate,EndDate,Modelname,branch_ID,c ustomer_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. -
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
4 7072
Instead of doing the following:
insertsql = "INTO Rent_Record ('Booking_ID')"
insertsql &= "values('" + Label7.Text + "')"
Why don't you just use "i+1"?
You aren't actually executing the SQL Insert command anywhere in code...could this be your problem?
i suspect either of the 2 reasons or both.
1) theres problem inserting with Booking_ID without inserting other fields under the REnt_REcord Table
2_ The insert of codes from 3 dropdownlist to variable StartDate and EndDate Variables at Line 74- 77 consist of error.
Please Assist.
Thanks Frinavale, i will check it out.
I have added a bunch of comments to your code.
You're code is confusing to me and you are going to have to explain things to me before I can continue to help you.
One thing I'd recommend is that you try your SQL queries in something like Query Analyzer to make sure that they work before attempting to use them in 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()
-
'I really don't understand what you are doing here
-
'You haven't specified any SQL query/command and yet
-
'you're calling the ExecuteScalar method to return you
-
'the first cell in the result set returned by the query ...
-
'What are you doing here?????
-
cmd3.Connection = con
-
Label5.Text = cmd3.ExecuteScalar()
-
-
-
If Not Page.IsPostBack Then
-
FillCarmodelList()
-
FillbranchList()
-
FillHourlist()
-
FillminuteList()
-
FilldayList()
-
Fillmonthlist()
-
End If
-
-
-
'Now this makes sense: you're supplying the command
-
'with an SQL query to execute. You're retrieving the
-
'first cell that results from the query ....
-
'but you're storing that value incremented by one
-
'in a label instead of using it in any programming logic.
-
'I think you are doing this in the wrong place...
-
'you should probably be doing this were you need to use the
-
'value returned....Please explain.
-
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"
-
-
'Ok now here comes the most confusing part.
-
'You're declaring a String that contains an SQL query
-
'(built on the value you stored in the label...instead of just using i+1...)
-
'But you never actually Use this query anywhere....
-
'You're just declaring it and aren't executing it.
-
'Even if you did execute this, and it worked properly....
-
'Why are you doing this in the Page Load event? It's going
-
'to be executed every time the page posts back.
-
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
-
-
'Are you crashing here??
-
'Is this where you're having problems?
-
'Have you tried stepping through this and checking if this is set correctly?
-
-
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") + "')")
-
-
'I think this is where you want to create a new entry in the Rent_Record table.
-
'First, grab the next available ID for the record and then insert a new record....
-
'instead of updating some record that you created during the page post back.
-
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
hey thanks~ i working out the SQL part.
Ok my final question. As u can see i got 2 set of 3Dropdownlists.
StartDate: Minute,Hour, Month
Enddate Minute Hour,Month
How do i get the data from drop downlist and insert to data. my Line 93-100 seems stupid.
Thank u so much
How to get Date
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ray |
last post by:
Date problem.
Using non American date formats with Microsoft Access and Visual Basic.
I set my regional settings to English(Ireland) or English(United Kingdom)
and my date appears in Access as...
|
by: rodneybauer1 |
last post by:
hello: thanks in advance for any responses.
i dont have a isp at home so have to use public library computer. will check
this every couple days though.
im using visual basic.Net windows XP with...
|
by: tshad |
last post by:
I can't seem to get insert into a DataGrid to work.
I am using an example from the net and made changes to work on my computer.
The grid comes up fine. The edit boxes in the footer are there. ...
|
by: Bob Achgill |
last post by:
I would like to use the timestamp on files to manage the
currency of support files for my VB windows application.
In this case I would only put the timestamp of the file
in the management database...
|
by: http://www.visual-basic-data-mining.net/forum |
last post by:
All,
I am attempting to insert a new row into an MS Access database using
VB.NET. This is an existing access database that I did not create, so I do
not know all of the field properties. I have...
|
by: hemant123 |
last post by:
Hi
I Am Trying To Insert Null Value In Oracle Date Column Using Visual Basic 6 Textbox. I Tried Various Options But Unable To Insert. Please Advise Me A Solution.
Thanks In Advance
Hemant
|
by: sandraz444 |
last post by:
I have an expression in the query under my form to autofill the date
under a certain condition but it wont write to the underlying table??
The date shows in the form but not the table. Does anyone...
|
by: veer |
last post by:
hello expert
i want to insert the date in one column of excel sheet but the date should be one which i enter in vb form
e,g i have a column name Date and i want to show the date which i select...
|
by: fniles |
last post by:
On my machine in the office I change the computer setting to English (UK) so
the date format is dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |