0

hi frnnds,
iam raghuram,
i had got a problem .when iam inserting the values in database ,it will not inserted.
i had done the coding ,but it doesn't show any mistakes.
while inserting the data it will show error on
insert.executenonquery()
so i requested pls give me the coding of inserting data into database........here iam using technologies are asp.net with vb.net,sqlserver-2005..

here my coding is given below as

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click
Dim name, desig, dept, addr, time_of_arr, remarks, prior_booking, booked_by As String
Dim booking_no, year, room_no, no_beds, amt As String
Dim date_of_dept, date_of_arr, booking_date As String
Dim connstr As String
connstr = ConfigurationManager.ConnectionStrings("guest1").ConnectionString()
Dim conn As New SqlConnection(connstr)
conn.Open()
booking_no = sino.Text
date_of_arr = CDate(dateofarrival.Text)
year = yea.Text
name = bookingname.Text
desig = designation.Text
dept = department.Text
addr = address.Text
room_no = roomno.Text
no_beds = noofbeds.Text
time_of_arr = arrivaltime.Text
date_of_dept = CDate(departuredate.Text)
amt = amount.Text
remarks = remark.Text
prior_booking = bookingname.Text
booked_by = requestedby.Text
booking_date = CDate(dateofbooking.Text)
Dim insert As New SqlCommand("insert into guesthouse (booking_no,date_of_arr ,year ,name,desig,dept,addr,room_no,no_beds,time_of_arr,date_of_dept ,amt,remarks,prior_booking,booked_by,booking_date) Values('" & booking_no & "' ,CONVERT(datetime ,'" & date_of_arr & "', 110), '" & year & "','" & name & "','" & desig & "','" & dept & "' ,'" & addr & "', '" & room_no & "','" & no_beds & "','" & time_of_arr & "',CONVERT(datetime ,'" & date_of_dept & "', 110),'" & amt & "','" & remarks & "','" & prior_booking & "','" & booked_by & "',CONVERT(datetime ,'" & booking_date & "', 110)", conn)
insert.ExecuteNonQuery()
conn.Close()
MsgBox("Message has been sent to the database")
End Sub

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Oxiegen
0

What is the error you recieve?

Perhaps you should implement some error checking like a try...catch.
Also, the use of CDate(...) always gives me a chill.
You should always make sure that the string passed into that method is a valid date.

Try this instead.

Dim dateString As String
Dim test As DateTime
If DateTime.TryParse(dateTextBox.Text,test) Then
     dateString = test.ToShortDateString()
End If
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.