 |
|
ช่วยดู code ให้หน่อยครับ บันทึกไม่ได้ติด Error (vb.net) |
|
 |
|
|
 |
 |
|
ช่วยดูให้หน่อยครับ มันบันทึกไม่สำเร็จ
aspx.vb
Code (VB.NET)
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
หน้า Code (ASP)
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="ProjectCap._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Cap Process Status</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="pnlAdd" runat="server">
<asp:Label ID="Label1" runat="server" Text="Order No."></asp:Label>
<asp:TextBox ID="txtOrderNo" runat="server" Width="189px"></asp:TextBox>
<br />
<br />
Status (Process)
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Height="17px" Width="80px">
<asp:ListItem Value="กรุณาเลือก Process">List Item</asp:ListItem>
<asp:ListItem Value="01"></asp:ListItem>
<asp:ListItem Value="02"></asp:ListItem>
<asp:ListItem Value="03"></asp:ListItem>
<asp:ListItem Value="04"></asp:ListItem>
<asp:ListItem Value="05"></asp:ListItem>
<asp:ListItem Value="06"></asp:ListItem>
<asp:ListItem Value="07"></asp:ListItem>
<asp:ListItem Value="08"></asp:ListItem>
<asp:ListItem Value="09"></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtStatus" runat="server" style="margin-left: 0px" Visible="False" Width="36px"></asp:TextBox>
<br />
<br />
Last Time
<asp:TextBox ID="txtDateTime" runat="server" Width="128px"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="BtnSave" runat="server" Text="Save" />
<br />
<br />
<asp:Label ID="lblStatus" runat="server" ForeColor="Red"></asp:Label>
</asp:Panel>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
<a href="http://www.mx7.com/view2/zkqC34ex8ChIkm56" target="_blank"><img border="0" src="http://www.mx7.com/i/a96/jwPFPR.JPG" /></a>
Tag : .NET, Ms SQL Server 2012, VBScript, Web (ASP.NET), VS 2012 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2016-08-31 14:26:54 |
By :
akarawoot |
View :
921 |
Reply :
11 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2016-08-31 14:27:40 |
By :
akarawoot |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตรง time, มั้งครับ
comma เกินมา
strSQL = "INSERT INTO table1(orderno,status,time,) " & _
|
 |
 |
 |
 |
Date :
2016-08-31 14:28:52 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณคุณ FONFIRE มากครับ พอลบ , ออก กดบันทึกมันขึ้นแบบนี้แทน
การบันทึกผิดพลาด(String or binary data would be truncated. The statement has been terminated.)
รบกวนด้วยครับ
|
 |
 |
 |
 |
Date :
2016-08-31 14:43:42 |
By :
akarawoot |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปิดกระทู้เลยครับ ทำได้แล้วครับ
ไปเพิ่มจำนวนเก็บข้อมูล ใน sql server varchar(20) ตอนแรก varchar10 ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2016-08-31 14:48:24 |
By :
akarawoot |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
String or binary data would be truncated ==>>> ข้อมูลยาวกว่า field ครับ
เช่นตั้งไว้เป็น nvarchar(10) แต่ตัวอักษรที่ insert เข้าไปมี 11
แก้ไขโดยการไปขยาย field ให้ใหญ่กว่าเดิม
|
 |
 |
 |
 |
Date :
2016-08-31 14:50:01 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO6 เดี๋ยวจะหาว่ามั่ว
มันควรจะถูกแทนที่ด้วย CSS
{
padding-left: 14; //ตามจำนวนที่เคาะ Space Bar
}
<asp:DropDownList ID="DropDownList1" runat="server"
--- แค่เปลี่ยนค่า มันก็ POST BACK ไปทั้งหน้าเลย (Page)
มันควรจะถูกแทนที่ด้วย JavaScript/Jquery
ติชมไปอย่างนั้นแหละ มันอาจจะมีวิธีอื่นฯที่ดีกว่านี้ก็อาจเป็นไปได้เหมือนกัน
Good luck.
|
 |
 |
 |
 |
Date :
2016-08-31 15:15:28 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แนะนำ CSS ในเบื้องต้น ถ้าไม่ระบุหมายถึง
Code (JavaScript)
{
padding: บน, ขวา, ล่าง, ซ้าย //นับจาก Ojbect นั้นฯ
}
สอนภาษาอังกฤษด้วย
ปล.
--- padding แปลว่า ถ่างออก/แหกออก
--- truncated แปลว่า ควรจะลดลง
|
 |
 |
 |
 |
Date :
2016-08-31 15:21:25 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO 9 มันมีที่มาและที่ไป เล่าให้ฟังก็ได้ (แบบสนุกฯ)
--- ตอนนั้นผมไปธุระที่จังหวัดภูเก็ต (หาเรื่องหนีเมียเที่ยวนั่นแลหะแต่ว่า แหม่มเยอะฉิบหายเลย)
แหม่มสาวฯสวยขนทอง/ผมทอง ตะโกนว่า "Lookat My Hair."
--- NO NO NO Please ใช้ตา ใช้ตา U อย่าใช้จมูกและลิ้น กับไอ (ผมไม่เข้าใจภาษาก็เลยใช้จมูก/ลิ้น)
+55555
|
 |
 |
 |
 |
Date :
2016-08-31 15:44:26 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณสำหรับคำแนะนำครับ
|
 |
 |
 |
 |
Date :
2016-08-31 20:49:02 |
By :
akarawoot |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|