String or binary data would be truncated.
The statement has been terminated
คือว่า ผิด ตรงไหน หรอคับ
โค๊ดคับ
Code (VB.NET)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim CurrYear As Integer = DateTime.Today.Year
ddl_Year.Items.Add((CurrYear - 1).ToString())
ddl_Year.Items.Add(CurrYear.ToString())
ddl_Year.Items.Add((CurrYear + 1).ToString())
ddl_Year.Items.Add((CurrYear + 2).ToString())
Dim CurrDay As DateTime = DateTime.Today
ddl_Day.SelectedValue = (CurrDay.Day).ToString()
ddl_Month.SelectedValue = (CurrDay.Month).ToString()
ddl_Year.SelectedValue = (CurrDay.Year).ToString()
End If
End Sub
Protected Sub Btn_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_Add.Click
If Trim(txt_I_discardID.Text) = "" Then
lbl_I_discardID.Visible = True
txt_I_discardID.Focus()
Return
End If
Dim connStr As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString.ToString()
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand()
cmd.CommandText = "INSERT INTO Table_discard(I_discardID,I_deviceID,I_storeName,I_storePay,I_discardCause,I_discardDate,I_Date,I_FileName)" & _
" VALUES(@I_discardID,@I_deviceID,@I_storeName,@I_storePay,@I_discardCause,@I_discardDate,@I_Date,@I_FileName) "
cmd.Parameters.Add("@I_discardID", SqlDbType.VarChar).Value = txt_I_discardID.Text
cmd.Parameters.Add("@I_deviceID", SqlDbType.VarChar).Value = txt_I_deviceID.Text
cmd.Parameters.Add("@I_storeName", SqlDbType.VarChar).Value = txt_I_storeName.Text
cmd.Parameters.Add("@I_storePay", SqlDbType.VarChar).Value = txt_I_storePay.Text
cmd.Parameters.Add("@I_discardCause", SqlDbType.VarChar).Value = txt_I_discardCause.Text
cmd.Parameters.Add("@I_discardDate", SqlDbType.VarChar).Value = Convert.ToDateTime(ddl_Day.SelectedValue & "/" & ddl_Month.SelectedValue & "/" & ddl_Year.SelectedValue)
cmd.Parameters.Add("@I_Date", SqlDbType.DateTime).Value = DateTime.Now
If Me.FileUpload1.HasFile Then
Me.FileUpload1.SaveAs(Server.MapPath("Picture/" & FileUpload1.FileName))
cmd.Parameters.Add("@I_FileName", SqlDbType.VarChar).Value = "Picture/" & FileUpload1.PostedFile.FileName
Else
cmd.Parameters.Add("@I_FileName", SqlDbType.VarChar).Value = ""
End If
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Response.Redirect("จำหน่าย.aspx")
GetData()
End Sub
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), VB.NET