0

我对这段代码有问题,错误是:字符串或二进制数据将被截断

    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

提前致谢

4

1 回答 1

0

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

在表 BOOKING_DETAILS 检查列数据类型。

于 2013-09-16T09:13:47.660 回答