需要快速修复sql错误

时间:2013-09-16 09:03:19

标签: asp.net sql database

我遇到了这段代码的问题,错误是:字符串或二进制数据会被截断

    Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
    Using cnnentry As New SqlConnection("Data Source=NB-1492\sqlipt;Initial Catalog=Bookings;Integrated Security=True;Pooling=False")
        Dim entrclientid As String
        Dim clid As New TextBox
        clid = FormView1.FindControl("txtclientid")
        entrclientid = clid.Text
        Dim sql As String = "INSERT INTO BOOKING_DETAILS(CLIENT_ID,BOOKING_DATE,REGO,CHECK_IN_DATE,CHECK_OUT_DATE,ROOM_ID) VALUES(@ROOM_ID,@CHECK_OUT_DATE,@CHECK_IN_DATE,@CLIENT_ID,@BOOKING_DATE,@REGO)"
        Dim cmdentry As New SqlCommand(sql, cnnentry)
        cmdentry.Parameters.AddWithValue("@CLIENT_ID", clid.Text)

        Dim curdate As New TextBox
        curdate = FormView1.FindControl("txtdate")
        cmdentry.Parameters.AddWithValue("@BOOKING_DATE", curdate.Text)

        Dim rego As New TextBox
        rego = FormView1.FindControl("RegoTextBox")
        cmdentry.Parameters.AddWithValue("@REGO", rego.Text)

        Dim textin As New TextBox
        textin = FormView1.FindControl("textcheckin")
        cmdentry.Parameters.AddWithValue("@CHECK_IN_DATE", textin.Text)

        Dim textout As New TextBox
        textout = FormView1.FindControl("textcheckout")
        cmdentry.Parameters.AddWithValue("@CHECK_OUT_DATE", textout.Text)

        Dim txtroomid As New TextBox
        txtroomid = Session.Item("room_tpe")
        cmdentry.Parameters.AddWithValue("@ROOM_ID", roomtype.Text)

        cnnentry.Open()
        strclid = cmdentry.ExecuteNonQuery()
        cnnentry.Close()
    End Using
End Sub

有人可以解释为什么我会收到这个错误吗?

表数据类型如下: Booking_ID int
Room_ID int
Check_In_Date nvarchar(MAX)
Check_Out_Date nvarchar(MAX)
Booking_Date nvarchar(MAX)
Client_ID nchar(11) Rego nvarchar(6)
Room_Cost money

提前致谢

1 个答案:

答案 0 :(得分:0)

您正在尝试将数据插入到无法由定义的数据类型保留的字段中。 例如:VARCHAR(3)无法保存' TestData'。

在表BOOKING_DETAILS中检查列数据类型。