Imports System.Data
Imports System.Data.SqlClient
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.txtDateTime.Text = Date.Now()
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Me.txtStatus.Text = Me.DropDownList1.SelectedItem.Text
End Sub
Protected Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim strConnString, strSQL As String
strConnString = "Server=localhost;UID=sa;PASSWORD=1234;database=Capdata;Max Pool Size=400;Connect Timeout=600;"
strSQL = "INSERT INTO table1(orderno,status,time,) " & _
" VALUES ('" & Me.txtOrderNo.Text & "','" & Me.txtStatus.Text & "','" & Me.txtDateTime.Text & "')"
objConn.ConnectionString = strConnString
objConn.Open()
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Try
objCmd.ExecuteNonQuery()
Me.lblStatus.Text = "บันทึกข้อมูลสำเร็จ"
Me.lblStatus.Visible = True
Catch ex As Exception
Me.lblStatus.Visible = True
Me.lblStatus.Text = "การบันทึกผิดพลาด(" & ex.Message & ")"
End Try
objConn.Close()
objConn = Nothing
End Sub
End Class
String or binary data would be truncated ==>>> ข้อมูลยาวกว่า field ครับ
เช่นตั้งไว้เป็น nvarchar(10) แต่ตัวอักษรที่ insert เข้าไปมี 11
แก้ไขโดยการไปขยาย field ให้ใหญ่กว่าเดิม
Date :
2016-08-31 14:50:01
By :
fonfire
No. 6
Guest
Quote:
String or binary data would be truncated ==>>> ข้อมูลยาวกว่า field ครับ
เช่นตั้งไว้เป็น nvarchar(10) แต่ตัวอักษรที่ insert เข้าไปมี 11
แก้ไขโดยการไปขยาย field ให้ใหญ่กว่าเดิม
The life must be learning all time and not finish. We never know that what will we met when we will have learning.
Even though, we perhaps meet good and bad person in the same time. Maybe this situation will be awaked us for continued learning by never ending.