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()
and the error is

"String or binary data would be truncated.
The statement has been terminated."


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..

reply me very urgently,,,,,,,,,,,,,

here my coding is given below as

Dim connstr As String
        connstr = ConfigurationManager.ConnectionStrings("guest1").ConnectionString()
        Dim conn As New SqlConnection(connstr)
        Dim booking_no, room_no, no_beds As Integer
        Dim date_of_arr, date_of_dept, booking_date As String
        Dim year, name, desig, dept, addr, time_of_arr, amt, remarks, prior_booking, booked_by As String
        Dim test As DateTime
        conn.Open()
        If DateTime.TryParse(dateofarrival.Text, test) Then
            date_of_arr = test.ToShortDateString()
        End If
        booking_no = sino.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
        If DateTime.TryParse(departuredate.Text, test) Then
            date_of_dept = test.ToShortDateString()
        End If
        amt = amount.Text
        remarks = remark.Text
        prior_booking = bookingname.Text
        booked_by = requestedby.Text
        If DateTime.TryParse(dateofbooking.Text, test) Then
            booking_date = test.ToShortDateString()
        End If
        Dim insert As New SqlClient.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 & "', 103),'" & year & "','" & name & "','" & desig & "','" & dept & "' ,'" & addr & "', '" & room_no & "','" & no_beds & "','" & time_of_arr & "',CONVERT(datetime ,'" & date_of_dept & "', 103),'" & amt & "','" & remarks & "','" & prior_booking & "','" & booked_by & "',CONVERT(datetime ,'" & booking_date & "', 103))", conn)
        insert.ExecuteNonQuery()
        conn.Close()
        MsgBox("record saved")
    End Sub

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Ramesh S
0

You are trying to insert values in a column in a table greater than the max length of the column specified.
Either increase the column width for the table in the database or check the length of the column values in your code before inserting into table.

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.