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,030

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



 

พี่ค่ะช่วยหน่อยค่ะ โปรแกรมมันทึกข้อมูลไม่ได้นะค่ะ มันขึ้น"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)
Private Sub btnSaveList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveList.Click

        If txtID_E.Text = "" Then
            MessageBox.Show("กรุณาระบุรหัสพนักงานก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtID_E.Focus()
            Exit Sub
        End If

        If lsvProductsList.Items.Count = 0 Then
            MessageBox.Show("กรุณาป้อนรายการสั่งซื้ออุปกรณ์ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtID_P.Focus()
            Exit Sub
        End If

        Dim sqlOrder As String = ""
        Dim comOrder As OleDbCommand = New OleDbCommand

        With Conn
            If .State = ConnectionState.Open Then .Close()
            .ConnectionString = strConn
            .Open()
        End With

        Try
            If MessageBox.Show("คุณต้องการบันทึกรายการการสั่งซื้ออุปกรณ์ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

                AutoGenerateNo_O()

               


                With comOrder
                    .CommandType = CommandType.Text
                    .CommandText = sqlOrder
                    .Connection = Conn
                    .ExecuteNonQuery()
                End With

                Dim i As Integer = 0

                Dim tmpID_P As String = ""
                Dim tmpNumber_O As Integer = 0

                Dim sqlProducts As String = ""
                'Dim tmpRemain_P As Integer = 0
                'Dim tmpNumber_W As Integer = 0
                'Dim tmpNumber_approval As Integer = 0
                Dim tmpDateOrder As Date
                tmpDateOrder = Date.Now

                For i = 0 To lsvProductsList.Items.Count - 1
                    sqlOrder = "INSERT INTO t_Order (Order_id,Order_Date,Order_PriceTotal,Employee_id) "
                    sqlOrder &= " VALUES('" & LastID_O & "',"
                    sqlOrder &= "'" & dtpDateOrder.Value & "',"
                    sqlOrder &= "'" & lblTotal.Text & "',"
                    sqlOrder &= "'" & txtID_E.Text & "')"

                    tmpID_P = lsvProductsList.Items(i).SubItems(0).Text
                    tmpNumber_O = CInt(lsvProductsList.Items(i).SubItems(3).Text)
                    ' tmpNumber_approval = CInt(lsvProductsList.Items(i).SubItems(3).Text)

                    sqlOrder &= "'" & tmpID_P & "',"
                    sqlOrder &= tmpNumber_O & ")"


                    With comOrder
                        .CommandText = sqlOrder
                        .ExecuteNonQuery()
                    End With

                Next

                frmMain.tslStatus.Text = "กำลังบันทึกข้อมูล..."
                MessageBox.Show("บันทึกรายการการสั่งซื้ออุปกรณ์เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
                frmMain.tslStatus.Text = ""

                If IsInstallPrinter() = True Then
                    If prDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
                        prDoc.Print()
                    End If
                Else
                    'MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    MessageBox.Show("คุณไม่ติดตั้ง Printer แล้วจะพิมพ์เอกสารได้ไงเล่า  555", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If

                ClearAllEmployeesData()
                ClearAllProductsData()

                lsvProductsList.Items.Clear()

                txtID_E.Enabled = True
                txtID_E.Focus()
            End If
        Catch ErrProcess As Exception
            MessageBox.Show("ไม่สามารถบันทึกรายการการสั่งซื้อได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End Try
    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 : 1151 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)
Private Sub btnSaveList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveList.Click

        If txtID_E.Text = "" Then
            MessageBox.Show("กรุณาระบุรหัสพนักงานก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtID_E.Focus()
            Exit Sub
        End If

        If lsvProductsList.Items.Count = 0 Then
            MessageBox.Show("กรุณาป้อนรายการสั่งซื้ออุปกรณ์ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtID_P.Focus()
            Exit Sub
        End If

        Dim sqlOrder As String = ""
        Dim comOrder As OleDbCommand = New OleDbCommand

        With Conn
            If .State = ConnectionState.Open Then .Close()
            .ConnectionString = strConn
            .Open()
        End With

        Try
            If MessageBox.Show("คุณต้องการบันทึกรายการการสั่งซื้ออุปกรณ์ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

                AutoGenerateNo_O()

               


                With comOrder
                    .CommandType = CommandType.Text
                    .CommandText = sqlOrder
                    .Connection = Conn
                    .ExecuteNonQuery()
                End With

                Dim i As Integer = 0

                Dim tmpID_P As String = ""
                Dim tmpNumber_O As Integer = 0

                Dim sqlProducts As String = ""
                'Dim tmpRemain_P As Integer = 0
                'Dim tmpNumber_W As Integer = 0
                'Dim tmpNumber_approval As Integer = 0
                Dim tmpDateOrder As Date
                tmpDateOrder = Date.Now

                For i = 0 To lsvProductsList.Items.Count - 1
                    sqlOrder = "INSERT INTO t_Order (Order_id,Order_Date,Order_PriceTotal,Employee_id,Product_id,Order_Quantity) "
                    sqlOrder &= " VALUES('" & LastID_O & "',"
                    sqlOrder &= "'" & dtpDateOrder.Value & "',"
                    sqlOrder &= "'" & lblTotal.Text & "',"
                    sqlOrder &= "'" & txtID_E.Text & "')"
                    sqlOrder &= "'" & tmpID_P & "',"
                    sqlOrder &= tmpNumber_O & ")"
                    tmpID_P = lsvProductsList.Items(i).SubItems(0).Text
                    sqlOrder = "INSERT INTO t_Order(Product_id,Order_Quantity)"

                    tmpNumber_O = CInt(lsvProductsList.Items(i).SubItems(3).Text)
                  


                    With comOrder
                        .CommandText = sqlOrder
                        .ExecuteNonQuery()
                    End With

                Next

                frmMain.tslStatus.Text = "กำลังบันทึกข้อมูล..."
                MessageBox.Show("บันทึกรายการการสั่งซื้ออุปกรณ์เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
                frmMain.tslStatus.Text = ""

                If IsInstallPrinter() = True Then
                    If prDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
                        prDoc.Print()
                    End If
                Else
                    MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)

                End If

                ClearAllEmployeesData()
                ClearAllProductsData()

                lsvProductsList.Items.Clear()

                txtID_E.Enabled = True
                txtID_E.Focus()
            End If
        Catch ErrProcess As Exception
            MessageBox.Show("ไม่สามารถบันทึกรายการการสั่งซื้อได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End Try
    End Sub

มันเกี่ยวกับตรงนี้ด้วยไหมค่ะ
  Private Sub AutoGenerateNo_O()
        Dim sqlTmp As String = ""
        Dim comTmp As OleDbCommand = New OleDbCommand
        Dim drTmp As OleDbDataReader
        Dim tmpID_O As Integer = 0

        sqlTmp = "SELECT TOP 1 Order_id FROM t_Order ORDER BY Order_id DESC"

        With Conn
            If .State = ConnectionState.Open Then .Close()
            .ConnectionString = strConn
            .Open()
        End With

        Try
            With comTmp
                .CommandType = CommandType.Text
                .CommandText = sqlTmp
                .Connection = Conn
                drTmp = .ExecuteReader()

                drTmp.Read()

                tmpID_O = CInt(CStr((drTmp.Item("Order_id"))))
                tmpID_O = tmpID_O + 1
                LastID_O = tmpID_O.ToString("00000")
            End With
        Catch
            LastID_O = "00001"
        End Try
    End Sub

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


 

No. 5



โพสกระทู้ ( 74,058 )
บทความ ( 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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