Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > พี่ค่ะช่วยหน่อยค่ะ โปรแกรมมันทึกข้อมูลไม่ได้นะค่ะ มันขึ้น"The changes you requested were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate da


 

[.NET] พี่ค่ะช่วยหน่อยค่ะ โปรแกรมมันทึกข้อมูลไม่ได้นะค่ะ มันขึ้น"The changes you requested were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate da

 
Topic : 077013



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์



Code (VB.NET)
01.Private Sub btnSaveList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveList.Click
02. 
03.        If txtID_E.Text = "" Then
04.            MessageBox.Show("กรุณาระบุรหัสพนักงานก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
05.            txtID_E.Focus()
06.            Exit Sub
07.        End If
08. 
09.        If lsvProductsList.Items.Count = 0 Then
10.            MessageBox.Show("กรุณาป้อนรายการสั่งซื้ออุปกรณ์ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
11.            txtID_P.Focus()
12.            Exit Sub
13.        End If
14. 
15.        Dim sqlOrder As String = ""
16.        Dim comOrder As OleDbCommand = New OleDbCommand
17. 
18.        With Conn
19.            If .State = ConnectionState.Open Then .Close()
20.            .ConnectionString = strConn
21.            .Open()
22.        End With
23. 
24.        Try
25.            If MessageBox.Show("คุณต้องการบันทึกรายการการสั่งซื้ออุปกรณ์ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
26. 
27.                AutoGenerateNo_O()
28. 
29.                
30. 
31. 
32.                With comOrder
33.                    .CommandType = CommandType.Text
34.                    .CommandText = sqlOrder
35.                    .Connection = Conn
36.                    .ExecuteNonQuery()
37.                End With
38. 
39.                Dim i As Integer = 0
40. 
41.                Dim tmpID_P As String = ""
42.                Dim tmpNumber_O As Integer = 0
43. 
44.                Dim sqlProducts As String = ""
45.                'Dim tmpRemain_P As Integer = 0
46.                'Dim tmpNumber_W As Integer = 0
47.                'Dim tmpNumber_approval As Integer = 0
48.                Dim tmpDateOrder As Date
49.                tmpDateOrder = Date.Now
50. 
51.                For i = 0 To lsvProductsList.Items.Count - 1
52.                    sqlOrder = "INSERT INTO t_Order (Order_id,Order_Date,Order_PriceTotal,Employee_id) "
53.                    sqlOrder &= " VALUES('" & LastID_O & "',"
54.                    sqlOrder &= "'" & dtpDateOrder.Value & "',"
55.                    sqlOrder &= "'" & lblTotal.Text & "',"
56.                    sqlOrder &= "'" & txtID_E.Text & "')"
57. 
58.                    tmpID_P = lsvProductsList.Items(i).SubItems(0).Text
59.                    tmpNumber_O = CInt(lsvProductsList.Items(i).SubItems(3).Text)
60.                    ' tmpNumber_approval = CInt(lsvProductsList.Items(i).SubItems(3).Text)
61. 
62.                    sqlOrder &= "'" & tmpID_P & "',"
63.                    sqlOrder &= tmpNumber_O & ")"
64. 
65. 
66.                    With comOrder
67.                        .CommandText = sqlOrder
68.                        .ExecuteNonQuery()
69.                    End With
70. 
71.                Next
72. 
73.                frmMain.tslStatus.Text = "กำลังบันทึกข้อมูล..."
74.                MessageBox.Show("บันทึกรายการการสั่งซื้ออุปกรณ์เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
75.                frmMain.tslStatus.Text = ""
76. 
77.                If IsInstallPrinter() = True Then
78.                    If prDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
79.                        prDoc.Print()
80.                    End If
81.                Else
82.                    'MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
83.                    MessageBox.Show("คุณไม่ติดตั้ง Printer แล้วจะพิมพ์เอกสารได้ไงเล่า  555", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
84.                End If
85. 
86.                ClearAllEmployeesData()
87.                ClearAllProductsData()
88. 
89.                lsvProductsList.Items.Clear()
90. 
91.                txtID_E.Enabled = True
92.                txtID_E.Focus()
93.            End If
94.        Catch ErrProcess As Exception
95.            MessageBox.Show("ไม่สามารถบันทึกรายการการสั่งซื้อได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
96.            Exit Sub
97.        End Try
98.    End Sub




Tag : .NET, Ms Access, VB.NET

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-04-12 19:52:23 By : Suduku View : 1218 Reply : 5
 

 

No. 1

Guest


อาจเป็นเพราะ Primary Key จะมีค่าซ้ำกันไม่ได้ครับ

ฟิลไหนที่เป็นคีย์หลัก ลองเปลี่ยนเป็น auto increment ดูครับหรือไม่ก็ Gen ใหม่ไม่ให้ซ้ำครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-04-12 20:55:33 By : ผ่านมาครับ
 

 

No. 2



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


ขอตัวอย่างหน่อยได้ไหมค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-04-12 21:26:27 By : Suduku
 

 

No. 3



โพสกระทู้ ( 130 )
บทความ ( 0 )



สถานะออฟไลน์


เค้าหมายถึงว่าตัว Database Access ของท่านที่กำหนดคีย์หลักเอาไว้ มันเป็นข้อมูลซ้ำกัน ซึ่งหน้าที่ของคีย์หลักก็คือไม่อนุญาติให้ใส่ข้อมูลซ้ำ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-04-12 21:29:21 By : manman12307
 

 

No. 4



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


มันขึ้น command text was not set for the command object

Code (VB.NET)
001.Private Sub btnSaveList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveList.Click
002. 
003.        If txtID_E.Text = "" Then
004.            MessageBox.Show("กรุณาระบุรหัสพนักงานก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
005.            txtID_E.Focus()
006.            Exit Sub
007.        End If
008. 
009.        If lsvProductsList.Items.Count = 0 Then
010.            MessageBox.Show("กรุณาป้อนรายการสั่งซื้ออุปกรณ์ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
011.            txtID_P.Focus()
012.            Exit Sub
013.        End If
014. 
015.        Dim sqlOrder As String = ""
016.        Dim comOrder As OleDbCommand = New OleDbCommand
017. 
018.        With Conn
019.            If .State = ConnectionState.Open Then .Close()
020.            .ConnectionString = strConn
021.            .Open()
022.        End With
023. 
024.        Try
025.            If MessageBox.Show("คุณต้องการบันทึกรายการการสั่งซื้ออุปกรณ์ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
026. 
027.                AutoGenerateNo_O()
028. 
029.                
030. 
031. 
032.                With comOrder
033.                    .CommandType = CommandType.Text
034.                    .CommandText = sqlOrder
035.                    .Connection = Conn
036.                    .ExecuteNonQuery()
037.                End With
038. 
039.                Dim i As Integer = 0
040. 
041.                Dim tmpID_P As String = ""
042.                Dim tmpNumber_O As Integer = 0
043. 
044.                Dim sqlProducts As String = ""
045.                'Dim tmpRemain_P As Integer = 0
046.                'Dim tmpNumber_W As Integer = 0
047.                'Dim tmpNumber_approval As Integer = 0
048.                Dim tmpDateOrder As Date
049.                tmpDateOrder = Date.Now
050. 
051.                For i = 0 To lsvProductsList.Items.Count - 1
052.                    sqlOrder = "INSERT INTO t_Order (Order_id,Order_Date,Order_PriceTotal,Employee_id,Product_id,Order_Quantity) "
053.                    sqlOrder &= " VALUES('" & LastID_O & "',"
054.                    sqlOrder &= "'" & dtpDateOrder.Value & "',"
055.                    sqlOrder &= "'" & lblTotal.Text & "',"
056.                    sqlOrder &= "'" & txtID_E.Text & "')"
057.                    sqlOrder &= "'" & tmpID_P & "',"
058.                    sqlOrder &= tmpNumber_O & ")"
059.                    tmpID_P = lsvProductsList.Items(i).SubItems(0).Text
060.                    sqlOrder = "INSERT INTO t_Order(Product_id,Order_Quantity)"
061. 
062.                    tmpNumber_O = CInt(lsvProductsList.Items(i).SubItems(3).Text)
063.                   
064. 
065. 
066.                    With comOrder
067.                        .CommandText = sqlOrder
068.                        .ExecuteNonQuery()
069.                    End With
070. 
071.                Next
072. 
073.                frmMain.tslStatus.Text = "กำลังบันทึกข้อมูล..."
074.                MessageBox.Show("บันทึกรายการการสั่งซื้ออุปกรณ์เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
075.                frmMain.tslStatus.Text = ""
076. 
077.                If IsInstallPrinter() = True Then
078.                    If prDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
079.                        prDoc.Print()
080.                    End If
081.                Else
082.                    MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
083. 
084.                End If
085. 
086.                ClearAllEmployeesData()
087.                ClearAllProductsData()
088. 
089.                lsvProductsList.Items.Clear()
090. 
091.                txtID_E.Enabled = True
092.                txtID_E.Focus()
093.            End If
094.        Catch ErrProcess As Exception
095.            MessageBox.Show("ไม่สามารถบันทึกรายการการสั่งซื้อได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
096.            Exit Sub
097.        End Try
098.    End Sub
099. 
100.มันเกี่ยวกับตรงนี้ด้วยไหมค่ะ
101.  Private Sub AutoGenerateNo_O()
102.        Dim sqlTmp As String = ""
103.        Dim comTmp As OleDbCommand = New OleDbCommand
104.        Dim drTmp As OleDbDataReader
105.        Dim tmpID_O As Integer = 0
106. 
107.        sqlTmp = "SELECT TOP 1 Order_id FROM t_Order ORDER BY Order_id DESC"
108. 
109.        With Conn
110.            If .State = ConnectionState.Open Then .Close()
111.            .ConnectionString = strConn
112.            .Open()
113.        End With
114. 
115.        Try
116.            With comTmp
117.                .CommandType = CommandType.Text
118.                .CommandText = sqlTmp
119.                .Connection = Conn
120.                drTmp = .ExecuteReader()
121. 
122.                drTmp.Read()
123. 
124.                tmpID_O = CInt(CStr((drTmp.Item("Order_id"))))
125.                tmpID_O = tmpID_O + 1
126.                LastID_O = tmpID_O.ToString("00000")
127.            End With
128.        Catch
129.            LastID_O = "00001"
130.        End Try
131.    End Sub

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-04-12 21:46:29 By : Suduku
 

 

No. 5



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
command text was not set for the command object


ช่วย Debug ดูหน่อยครับ ว่า Line ไหน Copy มาให้ดูด้วยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-04-16 21:30:10 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : พี่ค่ะช่วยหน่อยค่ะ โปรแกรมมันทึกข้อมูลไม่ได้นะค่ะ มันขึ้น"The changes you requested were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate da
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่