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

HOME > .NET Framework > Forum > กดปุ่ม button เพื่อที่จะย้ายข้อมูลจากตาราง A ไป B พร้อมลบข้อมูลจากตาราง A ทิ้ง แจ้ง object reference not set to an instance of an object



 

กดปุ่ม button เพื่อที่จะย้ายข้อมูลจากตาราง A ไป B พร้อมลบข้อมูลจากตาราง A ทิ้ง แจ้ง object reference not set to an instance of an object

 



Topic : 129474



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



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



รบกวนดูให้ด้วยครับไม่รู้ติดตรงไหน ตอน debug ก็ไม่แจ้ง error

Code (VB.NET)
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click

        open_database()
        Try

            If Label45.Text = "0" Then
                MessageBox.Show("Error! Number less than rows count ", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                tb01.Clear()
                tb01.Focus()

            ElseIf tb01.Text = Nothing Then
                MessageBox.Show("Error! กรุณาป้อนจำนวนที่ต้องการให้ถูกต้อง", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                tb01.Clear()
                tb01.Focus()

            ElseIf CInt(tb01.Text) = 0 Then
                MessageBox.Show("Error! กรุณาป้อนจำนวนที่ต้องการให้ถูกต้อง", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                tb01.Clear()
                tb01.Focus()

            ElseIf (tb01.Text) <> "" AndAlso (txtSearch.Text) = Nothing Then
                MessageBox.Show("ผิดพลาด! ไม่สามารถจองได้หากยังไม่ได้เลือกวัตถุดิบ/Error! You have to select Material", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                tb01.Clear()
                tb01.Focus()

            ElseIf CInt(tb01.Text) > 100 Then
                MessageBox.Show("Error! Number less than 100", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                tb01.Clear()
                tb01.Focus()

            ElseIf (tb01.Text) > dgv02.Rows.Count Then
                MessageBox.Show("Error! Number less than rows count", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                tb01.Clear()
                tb01.Focus()
            Else

                Dim start As Integer = dgv02.CurrentCell.RowIndex
                For i As Integer = start To (start + CInt(tb01.Text)) - 1

                    If Not dgv02.Rows(i).IsNewRow Then
                        sql = "insert into reservation1 (id, product_id, product_name, product_warehouse," & _
                            "product_amount, product_qty, product_lotno, product_color, product_date, mat_return, " & _
                            "boi, location, product_datereservation, expired_date, expired_ready, expired_warning) " & _
                            "values (@id, @product_id, @product_name, @product_warehouse, @product_amount, @product_qty, @product_lotno, " & _
                            "@product_color, @product_date, @mat_return, @boi, @location, @product_datereservation, " & _
                            "@expired_date, @expired_ready, @expired_warning)"
                        sql &= "delete from in_stock1 where product_id='" & dgv02.Rows(i).Cells(1).Value & "';"

                        cmd = New System.Data.SqlClient.SqlCommand(sql, cn)
                        With cmd
                            .Parameters.Add(New SqlParameter("@id", dgv02.Rows(i).Cells(0).Value))
                            .Parameters.Add(New SqlParameter("@product_id", dgv02.Rows(i).Cells(1).Value))
                            .Parameters.Add(New SqlParameter("@product_name", dgv02.Rows(i).Cells(2).Value))
                            .Parameters.Add(New SqlParameter("@product_warehouse", dgv02.Rows(i).Cells(3).Value))
                            .Parameters.Add(New SqlParameter("@product_amount", dgv02.Rows(i).Cells(4).Value))
                            .Parameters.Add(New SqlParameter("@product_qty", dgv02.Rows(i).Cells(5).Value))
                            .Parameters.Add(New SqlParameter("@product_lotno", dgv02.Rows(i).Cells(6).Value))
                            .Parameters.Add(New SqlParameter("@product_color", dgv02.Rows(i).Cells(7).Value))
                            .Parameters.Add(New SqlParameter("@product_date", dgv02.Rows(i).Cells(8).Value))
                            .Parameters.Add(New SqlParameter("@mat_return", dgv02.Rows(i).Cells(9).Value))
                            .Parameters.Add(New SqlParameter("@boi", dgv02.Rows(i).Cells(10).Value))
                            .Parameters.Add(New SqlParameter("@location", dgv02.Rows(i).Cells(11).Value))
                            .Parameters.Add(New SqlParameter("@product_datereservation", DateTime.Now.ToString("yyyy-MM-dd")))
                            .Parameters.Add(New SqlParameter("@expired_date", dgv02.Rows(i).Cells(12).Value))
                            .Parameters.Add(New SqlParameter("@expired_ready", dgv02.Rows(i).Cells(13).Value))
                            .Parameters.Add(New SqlParameter("@expired_warning", dgv02.Rows(i).Cells(14).Value))
                        End With
                        cmd.ExecuteNonQuery()
                    End If
                Next
                loaddb("select * from in_stock1 where product_name='" & txtSearch.Text & "' and product_color='" & txtColorSearch.Text & "'")
                loaddbdgv2("select * from in_stock1 where product_name='" & txtSearch.Text & "' and product_color='" & txtColorSearch.Text & "'")
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        cn.Close()
        load_dgv01()

        load_dgv2()
        sumDgv002()
        tb01.Clear()
        tb01.Focus()
        'dgv02.Sort(dgv02.Columns(8), System.ComponentModel.ListSortDirection.Ascending)

        dgv2.NewRowIndex.ToString(txtSearch.Text)
        For i = dgv2.RowCount - 1 To 0 Step -1
            If dgv2.Rows.Item(i).Cells(0).Value = txtSearch.Text And dgv2.Rows.Item(i).Cells(1).Value = txtColorSearch.Text And dgv2.Rows.Item(i).Cells(1).Value = txtType.Text Then

                dgv2.Rows(i).Selected = True
                Me.dgv2.CurrentCell = Me.dgv2.Rows(i).Cells(0)
            End If
        Next

        txtSearch.Text = ""
        txtColorSearch.Text = ""
        txtType.Text = ""

    End Sub




Tag : .NET, VS 2012 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-11-14 11:05:03 By : sakkapong View : 843 Reply : 3
 

 

No. 1



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



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

ลองเช็ค If Not dgv02.Rows(i).IsNewRow Then ดูรึยังครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-11-14 11:49:38 By : lamaka.tor
 


 

No. 2



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



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

ผมลองสังเกตดูถ้าผมใช้เม้าส์คลิ๊กเพื่อให้เกิดสามเหลี่ยม อยู่ด้านหน้าจะไม่มีปัญหาครับ แต่พอผมเปิดโปรแกรมขึ้นมามันไม่มี สามเหลี่ยมด้านหน้าครับจึงเกิด Error แนะนำวิธี Focus แล้วมีสามเหลี่ยมด้านหน้าด้วยครับ
asdfasdfdsaf
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-11-14 13:10:32 By : sakkapong
 

 

No. 3



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



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

ได้แล้วครับ ผมเปลี่ยนการแสดงผลของ datagrid ใหม่ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-11-14 16:02:08 By : sakkapong
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : กดปุ่ม button เพื่อที่จะย้ายข้อมูลจากตาราง A ไป B พร้อมลบข้อมูลจากตาราง A ทิ้ง แจ้ง object reference not set to an instance of an object
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 04
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 อัตราราคา คลิกที่นี่