 |
|
[.NET]
ช่วยแนะวิธีการ error vb 2005 นี้ด้วยครับ ผมเขียนโปรแรกมาแล้วมันเกิด error มายังนีครับ vb.2005 |
|
 |
|
|
 |
 |
|
ผมเขียนโปรแรกมาแล้วมันเกิด error มายังนีครับ
vb.2005
"String or binary data would be truncated. The statement has been terminated."
โค้ดมีอย่างนี้ครับ
'การตรวจสอบ
Dim dt As DataTable
sql = " select * from Patient "
sql &= " where Id_Card = '" & Id_Card.Text & "'"
da = New SqlDataAdapter(sql, con)
dt = New DataTable
da.Fill(dt)
If dt.Rows.Count > 0 Then
MessageBox.Show("มีหมายเลขบัตรประชาชน นี้แล้วครับ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Id_Card.Focus()
Id_Card.Text = ""
Exit Sub
End If
If MessageBox.Show("คุณต้องการบันทึกข้อมูลนี้ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Try
sb = New StringBuilder
'sb.Append("insert into Patient(Id_Card, Titlecode_Id, Name, Birthday, Sex, Status_Id, Occ_Id, Nationality, Origin, religion, Patient_Father, Patient_Mother, Allergic, Patient_Mate, Address, Moo, Villiage, Tumbol, Amphur, Province, Life, Phone, Righttype, Right_Id)")
'sb.Append(" values (@Id_Card, @Titlecode_Id, @Name, @Birthday, @Sex, @Status_Id, @Occ_Id, @Nationality, @Origin, @religion, @Patient_Father, @Patient_Mother, @Allergic, @Patient_Mate, @Address, @Moo, @Villiage, @Tumbol, @Amphur, @Province, @Life, @Phone, @Righttype, @Right_Id)")
sb.Append("insert into Patient(Id_Card, Titlecode_Id, Name, Birthday, Sex, Status_Id, Occ_Id, Nationality, Origin, religion, Allergic, Address, Villiage, Tumbol, Amphur, Province, Life, Phone, Righttype, Right_Id)")
sb.Append(" values (@Id_Card, @Titlecode_Id, @Name, @Birthday, @Sex, @Status_Id, @Occ_Id, @Nationality, @Origin, @religion, @Allergic, @Address, @Villiage, @Tumbol, @Amphur, @Province, @Life, @Phone, @Righttype, @Right_Id)")
Dim insert As String = sb.ToString
com = New SqlCommand
With com
.CommandText = insert
.CommandType = CommandType.Text
.Connection = con
.Parameters.Clear()
.Parameters.Add("@Id_Card", SqlDbType.VarChar).Value = Id_Card.Text
.Parameters.Add("@Titlecode_Id", SqlDbType.VarChar).Value = title.Text
.Parameters.Add("@Name", SqlDbType.VarChar).Value = namepatien.Text
.Parameters.Add("@Birthday", SqlDbType.DateTime).Value = birthday.Value.Date
.Parameters.Add("@Sex", SqlDbType.VarChar).Value = sex.Text
.Parameters.Add("@Status_Id", SqlDbType.VarChar).Value = status.Text
.Parameters.Add("@Occ_Id", SqlDbType.VarChar).Value = occ.Text
.Parameters.Add("@Nationality", SqlDbType.VarChar).Value = nationality.Text
.Parameters.Add("@Origin", SqlDbType.VarChar).Value = origin.Text
.Parameters.Add("@Religion", SqlDbType.VarChar).Value = religion.Text
.Parameters.Add("@Patient_Father", SqlDbType.VarChar).Value = nameF.Text
.Parameters.Add("@Patient_Mother", SqlDbType.VarChar).Value = nameM.Text
.Parameters.Add("@Allergic", SqlDbType.VarChar).Value = remark.Text
.Parameters.Add("@Patient_Mate", SqlDbType.VarChar).Value = nameMate.Text
.Parameters.Add("@Address", SqlDbType.VarChar).Value = Nohouse.Text
.Parameters.Add("@Moo", SqlDbType.VarChar).Value = Moo.Text
.Parameters.Add("@Villiage", SqlDbType.VarChar).Value = villiagename.Text
.Parameters.Add("@Tumbol", SqlDbType.VarChar).Value = tumbol.Text
.Parameters.Add("@Amphur", SqlDbType.VarChar).Value = amphur.Text
.Parameters.Add("@Province", SqlDbType.VarChar).Value = province.Text
.Parameters.Add("@Life", SqlDbType.VarChar).Value = life.Text
.Parameters.Add("@Phone", SqlDbType.VarChar).Value = phone.Text
.Parameters.Add("@Righttype", SqlDbType.VarChar).Value = rightname.Text
.Parameters.Add("@Right_Id", SqlDbType.VarChar).Value = Right_Id.Text
Dim result As Integer = .ExecuteNonQuery
If result = 0 Then
MessageBox.Show("ไม่สามารถบันทึกข้อมูลได้", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
ShowData()
cldata()
End With
Catch ex As Exception
MessageBox.Show("เกิดข้อผิดพลาดขึ้น เนื่องจาก " & ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End If
ช่วยด้วยครับ
เครียดมากเลย แนะวิธีแก้ไขด้วยเถอะครับ
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-05-23 23:08:06 |
By :
takamachi |
View :
1704 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตาลายเลย ก็อบไว้ก่อน จะได้ดูง่ายๆ
Code (VB.NET)
01.
02. Dim dt As DataTable
03. sql = " select * from Patient "
04. sql &= " where Id_Card = '" & Id_Card.Text & "'"
05.
06. da = New SqlDataAdapter(sql, con)
07. dt = New DataTable
08. da.Fill(dt)
09. If dt.Rows.Count > 0 Then
10. MessageBox.Show( "มีหมายเลขบัตรประชาชน นี้แล้วครับ !!!" , "ผลการตรวจสอบ" , MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
11. Id_Card.Focus()
12. Id_Card.Text = ""
13. Exit Sub
14. End If
15.
16. If MessageBox.Show( "คุณต้องการบันทึกข้อมูลนี้ ใช่หรือไม่?" , "คำยืนยัน" , MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
17. Try
18. sb = New StringBuilder
19.
20.
21. sb.Append( "insert into Patient(Id_Card, Titlecode_Id, Name, Birthday, Sex, Status_Id, Occ_Id, Nationality, Origin, religion, Allergic, Address, Villiage, Tumbol, Amphur, Province, Life, Phone, Righttype, Right_Id)" )
22. sb.Append( " values (@Id_Card, @Titlecode_Id, @Name, @Birthday, @Sex, @Status_Id, @Occ_Id, @Nationality, @Origin, @religion, @Allergic, @Address, @Villiage, @Tumbol, @Amphur, @Province, @Life, @Phone, @Righttype, @Right_Id)" )
23. Dim insert As String = sb.ToString
24. com = New SqlCommand
25. With com
26. .CommandText = insert
27. .CommandType = CommandType.Text
28. .Connection = con
29. .Parameters.Clear()
30. .Parameters.Add( "@Id_Card" , SqlDbType.VarChar).Value = Id_Card.Text
31. .Parameters.Add( "@Titlecode_Id" , SqlDbType.VarChar).Value = title.Text
32. .Parameters.Add( "@Name" , SqlDbType.VarChar).Value = namepatien.Text
33. .Parameters.Add( "@Birthday" , SqlDbType.DateTime).Value = birthday.Value. Date
34. .Parameters.Add( "@Sex" , SqlDbType.VarChar).Value = sex.Text
35. .Parameters.Add( "@Status_Id" , SqlDbType.VarChar).Value = status.Text
36.
37. .Parameters.Add( "@Occ_Id" , SqlDbType.VarChar).Value = occ.Text
38. .Parameters.Add( "@Nationality" , SqlDbType.VarChar).Value = nationality.Text
39. .Parameters.Add( "@Origin" , SqlDbType.VarChar).Value = origin.Text
40. .Parameters.Add( "@Religion" , SqlDbType.VarChar).Value = religion.Text
41. .Parameters.Add( "@Patient_Father" , SqlDbType.VarChar).Value = nameF.Text
42. .Parameters.Add( "@Patient_Mother" , SqlDbType.VarChar).Value = nameM.Text
43. .Parameters.Add( "@Allergic" , SqlDbType.VarChar).Value = remark.Text
44. .Parameters.Add( "@Patient_Mate" , SqlDbType.VarChar).Value = nameMate.Text
45. .Parameters.Add( "@Address" , SqlDbType.VarChar).Value = Nohouse.Text
46. .Parameters.Add( "@Moo" , SqlDbType.VarChar).Value = Moo.Text
47. .Parameters.Add( "@Villiage" , SqlDbType.VarChar).Value = villiagename.Text
48. .Parameters.Add( "@Tumbol" , SqlDbType.VarChar).Value = tumbol.Text
49. .Parameters.Add( "@Amphur" , SqlDbType.VarChar).Value = amphur.Text
50. .Parameters.Add( "@Province" , SqlDbType.VarChar).Value = province.Text
51. .Parameters.Add( "@Life" , SqlDbType.VarChar).Value = life.Text
52. .Parameters.Add( "@Phone" , SqlDbType.VarChar).Value = phone.Text
53. .Parameters.Add( "@Righttype" , SqlDbType.VarChar).Value = rightname.Text
54. .Parameters.Add( "@Right_Id" , SqlDbType.VarChar).Value = Right_Id.Text
55. Dim result As Integer = .ExecuteNonQuery
56. If result = 0 Then
57. MessageBox.Show( "ไม่สามารถบันทึกข้อมูลได้" , "ผลการทำงาน" , MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
58. Else
59. MessageBox.Show( "บันทึกข้อมูลเรียบร้อย" , "ผลการทำงาน" , MessageBoxButtons.OK, MessageBoxIcon.Information)
60. End If
61. ShowData()
62. cldata()
63. End With
64. Catch ex As Exception
65. MessageBox.Show( "เกิดข้อผิดพลาดขึ้น เนื่องจาก " & ex.Message, "ผลการทำงาน" , MessageBoxButtons.OK, MessageBoxIcon.Information)
66. End Try
67. End If
|
 |
 |
 |
 |
Date :
2010-05-24 00:09:15 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|