 |
|
จะทำการเพิ่มข้อมูลลงฐานข้อมูลMySQL จาก VB2008 แต่ติดปัญหาช่วยทีครับผู้รู้ |
|
 |
|
|
 |
 |
|
คือว่าผมกำลังทำโค๊ดข้อมูลทำการเพิ่มข้อมูลลงในฐานข้อมูลที่เชื่อมต่อกับ MySql กับ VB2008
Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Public Class FrmCustomer
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
If CusID.Text = "" Then
MsgBox("กรุณากรอกรหัสลูกค้า")
ElseIf CusName.Text = "" Then
MsgBox("กรุณากรอกกรอกชื่อ")
ElseIf CusLname.Text = "" Then
MsgBox("กรุณากรอกนามสกุล")
ElseIf CusIDCard.Text = "" Then
MsgBox("กรุณากรอกรหัสบัตรประชาชน")
ElseIf CusTel.Text = "" Then
MsgBox("กรุณากรอกเบอร์โทรศัพท์")
ElseIf CusAddress.Text = "" Then
MsgBox("กรุณากรอกที่อยู่")
End If
Dim sex As String = ""
If male.Checked Then
sex = "0"
Else
sex = "1"
End If
Dim conn As New SqlConnection
conn.ConnectionString = "Data Source=ASUS\SQLEXPRESS;Initial Catalog='Travel Raft Rent System';Integrated Security=True"
conn.Open()
Dim myCommand As New SqlCommand("INSERT INTO customer VALUES('" & CusID.Text & "','" & CusName.Text & "','" & CusLname.Text & "','" & sex & "','" & CusIDCard.Text & "','" & CusTel.Text & "', '" & CusAddress.Text & "', '" & CusEmail.Text & "')", conn)
myCommand.ExecuteNonQuery()
MsgBox("ระบบทำการบันทึกข้อมูลเรียบร้อยแล้ว")
End Sub
End Class
พอทำการเพิ่มแล้วมันขึ้นแจ้งเตือนเป็นแท็ปคลุมสีเหลือง แบบในรูปครับต้องแก้ยังไงครับ

Tag : MySQL, VB.NET, VS 2008 (.NET 3.x)
|
|
 |
 |
 |
 |
Date :
2013-02-25 18:38:44 |
By :
mai32093 |
View :
1112 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Error นี้เกิดจาก ขอบเขตของข้อมูลไม่พอดีกับข้อมูลครับ เช่น Varchar (50) แต่ไปรับ 60 ตัวอักษร 
|
 |
 |
 |
 |
Date :
2013-02-25 19:35:15 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2013-02-25 19:35:15
รายละเอียดของการตอบ ::
ผมลองแก้ไขแล้วครับ ปัญหาหลักคือมันให้ผมกำหนดที่อยู่ของฟิลแบบตายตัวอ่ะครับพอแก้แล้วใส่ข้อมูลแบบไม่มีปัญหาอะไรเลย
แก้เป็นแบบนี้อ่ะครับ
Code
Dim myCommand As New SqlCommand("INSERT INTO Customer (Cus_ID,Cus_Name,Cus_Lname,Cus_Sex,Cus_IDCard,Cus_Tel,Cus_Address,Cus_Email)VALUES('" & CusID.Text & "','" & CusName.Text & "','" & CusLname.Text & "','" & sex & "','" & CusIDCard.Text & "','" & CusTel.Text & "', '" & CusAddress.Text & "', '" & CusEmail.Text & "')", conn)
งงเลยทีเด่วพอแก้แบบนี้ได้เฉยๆเลย
|
 |
 |
 |
 |
Date :
2013-02-25 19:48:55 |
By :
mai32093 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2013-02-25 19:55:29 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|