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 > สอบถามเกี่ยวกับการ Delete ข้อมูล ของ WinCe code vb.net แต่ Insert และ Update สามารถเพิ่มข้อมูลได้ครับ



 

สอบถามเกี่ยวกับการ Delete ข้อมูล ของ WinCe code vb.net แต่ Insert และ Update สามารถเพิ่มข้อมูลได้ครับ

 



Topic : 094590



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



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



Code ด้านล่าง Insert กับ Update สามารถทำงานได้แต่ Code Delete ต้องเขียนยังไงครับ ยังทำไม่ได้เลยครับ

หลัการทำงาน ดังนี้
คือว่า ต้องการให้ ข้อมูลในฐานข้อมูลที่อยู่ในโปรแกรม ลบตามข้อมูลใน Server สมมุติว่า ฐานข้อมูลใน Server ก่อนหน้าที่จะลบ มีจำนวน 25 ตัว หลังจากลบแล้วเหลือ 20 ตัว ส่วนในโปรแกรมครั้งแรกมี 25 ตัว ต้องการลบ 5 ตัว เพื่อให้ข้อมูลเท่ากันทั้ง 2 โปรแกรม ต้องทำอย่างไรครับ

รบกวนด้วยครับ
ขอบคุณครับ

Code (VB.NET)
    Sub deleteData()
        Dim cmd As New SqlCommand
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        Dim ds As New DataSet
        Dim strID As Integer '= 27
        Dim strPartNo As String
        Dim strFunc As String
        Dim strHandle As String
        Dim strMirror As String
        Dim strUserDef1 As String
        Dim strUserDef2 As String
        Dim strUserDef3 As String
        Dim strUserDef4 As String
        Dim strUserDef5 As String
        Dim i As Integer = 1
       
        Try
            ' i = tempMaxsrvqgateDelete

            ' For i = tempMaxsrvqgateDelete To tempMaxsrvArmDelete
            'i = tempMaxsrvArmDelete - 1
            ' If i = tempMaxsrvArmDelete Then
            'Exit Sub
            ' Else
            i = i + tempMaxsrvqgateDelete

            ' With cmd
            '.Connection = mycon
            '.CommandType = CommandType.Text
            ' .CommandText = "select * from Tape"
            '  End With
            'da.SelectCommand = cmd
            ' da.Fill(ds, "show") 'Keep data to Dataset
            ' strID = ds.Tables("show").Rows.Item(i - 1)("ID").ToString
            strID = i
            '  While (tempMaxsrvQgate < tempMaxsrvArm)
            'tempMaxsrvArm = tempMaxsrvArm - 1

            ' strPartNo = ds.Tables("show").Rows.Item(tempMaxsrvqgateDelete)("Partno").ToString
            ' strFunc = ds.Tables("show").Rows.Item(tempMaxsrvqgateDelete)("Func").ToString
            'strHandle = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Handle").ToString
            'strMirror = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Mirror").ToString
            'strUserDef1 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef1").ToString
            'strUserDef2 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef2").ToString
            'strUserDef3 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef3").ToString
            ' strUserDef4 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef4").ToString
            ' strUserDef5 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef5").ToString

            With cmdCE
                .Connection = conCE
                .CommandType = CommandType.Text
                .CommandText = "delete from [Tape] " & _
                "Where id = '" & strID & "'"
                ' "Where id = '" & strID & "'and Partno = '" & strPartNo & "' "
            End With


            cmdCE.ExecuteNonQuery()

            '  End If

            ' Next
            ' End While
            ' MessageBox.Show("Save Successfully")
            ShowData()
            ' conCE.Close()
        Catch exsql As SqlCeException
            MsgBox(exsql.Message, MsgBoxStyle.Exclamation)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub


    Sub updateData()
        Dim cmd As New SqlCommand
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        Dim ds As New DataSet
        Dim strID As Integer
        Dim strPartNo As String
        Dim strFunc As String
        Dim strHandle As String
        Dim strMirror As String
        Dim strUserDef1 As String
        Dim strUserDef2 As String
        Dim strUserDef3 As String
        Dim strUserDef4 As String
        Dim strUserDef5 As String
        Dim tempMaxsrvQgateUP As Integer
        Dim tempMaxsrvArmUP As Integer


        Try
            With cmd
                .Connection = mycon
                .CommandType = CommandType.Text
                .CommandText = "select max(ID) as maxsrvQgateUP from Tape"
            End With
            da.SelectCommand = cmd
            da.Fill(ds, "Show") 'Keep data to Dataset
            tempMaxsrvQgateUP = ds.Tables("show").Rows(0)(0).ToString



            'Select Data from srvARM
            With cmdCE
                .Connection = conCE
                .CommandType = CommandType.Text
                .CommandText = "select max(ID) as maxsrvArmUP from Tape"
            End With
            daCE = New SqlCeDataAdapter(cmdCE)
            daCE.Fill(dtCE) 'Keep data to Datatable
            tempMaxsrvArmUP = dtCE.Rows(0)(0).ToString

            tempMaxsrvQgateUP = tempMaxsrvQgateUP + 1
            tempMaxsrvArmUP = tempMaxsrvArmUP + 1

            While (tempMaxsrvQgateUP <> 1)
                tempMaxsrvQgateUP = tempMaxsrvQgateUP - 1
                tempMaxsrvArmUP = tempMaxsrvArmUP - 1

                With cmd
                    .Connection = mycon
                    .CommandType = CommandType.Text
                    .CommandText = "select * from Tape"
                End With
                da.SelectCommand = cmd
                da.Fill(ds, "show") 'Keep data to Dataset
                strID = ds.Tables("show").Rows(tempMaxsrvArmUP)("ID")
                strPartNo = ds.Tables("show").Rows.Item(tempMaxsrvArmUP)("Partno").ToString
                strFunc = ds.Tables("show").Rows.Item(tempMaxsrvArmUP)("Func").ToString
                strHandle = ds.Tables("show").Rows.Item(tempMaxsrvArmUP)("Handle").ToString
                strMirror = ds.Tables("show").Rows.Item(tempMaxsrvArmUP)("Mirror").ToString
                strUserDef1 = ds.Tables("show").Rows.Item(tempMaxsrvArmUP)("UserDef1").ToString
                strUserDef2 = ds.Tables("show").Rows.Item(tempMaxsrvArmUP)("UserDef2").ToString
                strUserDef3 = ds.Tables("show").Rows.Item(tempMaxsrvArmUP)("UserDef3").ToString
                strUserDef4 = ds.Tables("show").Rows.Item(tempMaxsrvArmUP)("UserDef4").ToString
                strUserDef5 = ds.Tables("show").Rows.Item(tempMaxsrvArmUP)("UserDef5").ToString

                With cmdCE
                    .Connection = conCE
                    .CommandType = CommandType.Text
                    .CommandText = "UPDATE Tape SET " & _
                    "Func = '" & strFunc & "',Handle='" & strHandle & "',Mirror='" & strMirror & "',UserDef1='" & strUserDef1 & "',UserDef2='" & strUserDef2 & "',UserDef3='" & strUserDef3 & "',UserDef4='" & strUserDef4 & "',UserDef5='" & strUserDef5 & "' " & _
                    "Where id = '" & strID & "'and Partno = '" & strPartNo & "' "
                End With
                cmdCE.ExecuteNonQuery()
            End While
            MessageBox.Show("Update Successfully")
            ShowData()
            conCE.Close()
        Catch exsql As SqlCeException
            MsgBox(exsql.Message, MsgBoxStyle.Exclamation)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub
    Sub insertData()
        Dim cmd As New SqlCommand
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        Dim ds As New DataSet
        Dim strID As Integer
        Dim strPartNo As String
        Dim strFunc As String
        Dim strHandle As String
        Dim strMirror As String
        Dim strUserDef1 As String
        Dim strUserDef2 As String
        Dim strUserDef3 As String
        Dim strUserDef4 As String
        Dim strUserDef5 As String

        Try

            While (tempMaxsrvArm < tempMaxsrvQgate)
                tempMaxsrvArm = tempMaxsrvArm + 1

                With cmd
                    .Connection = mycon
                    .CommandType = CommandType.Text
                    .CommandText = "select * from Tape"
                End With
                da.SelectCommand = cmd
                da.Fill(ds, "show") 'Keep data to Dataset
                strID = ds.Tables("show").Rows.Add(tempMaxsrvArm)("ID").ToString
                strPartNo = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Partno").ToString
                strFunc = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Func").ToString
                strHandle = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Handle").ToString
                strMirror = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Mirror").ToString
                strUserDef1 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef1").ToString
                strUserDef2 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef2").ToString
                strUserDef3 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef3").ToString
                strUserDef4 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef4").ToString
                strUserDef5 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef5").ToString

                With cmdCE
                    .Connection = conCE
                    .CommandType = CommandType.Text
                    .CommandText = "INSERT INTO [Tape] ([ID], [PartNo],Func,Handle,mirror,UserDef1,UserDef2,UserDef3,UserDef4,UserDef5) VALUES  " & _
                     "('" & strID & "','" & strPartNo & "','" & strFunc & "','" & strHandle & "','" & strMirror & "','" & strUserDef1 & "','" & strUserDef2 & "','" & strUserDef3 & "','" & strUserDef4 & "','" & strUserDef5 & "')"
                End With


                cmdCE.ExecuteNonQuery()




            End While
            ' MessageBox.Show("Save Successfully")
            ShowData()
            conCE.Close()
        Catch exsql As SqlCeException
            MsgBox(exsql.Message, MsgBoxStyle.Exclamation)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub




Tag : .NET, Ms SQL Server 2005, VB.NET







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-05-02 15:10:06 By : s_oil_p View : 1055 Reply : 2
 

 

No. 1



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



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

code ด้านล่างนี้ Delete ข้อมูลได้แล้วนะครับ
Code (VB.NET)
 Sub deleteData()
        Dim cmd As New SqlCommand
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        Dim ds As New DataSet
        Dim strID As Integer '= 27
        Dim strPartNo As String

        Try


            While (tempMaxsrvQgate <= tempMaxsrvArm)
                tempMaxsrvQgate = tempMaxsrvQgate + 1

                With cmdCE
                    .Connection = conCE
                    .CommandType = CommandType.Text
                    .CommandText = "select * from Tape"
                End With
                daCE = New SqlCeDataAdapter(cmdCE)
                daCE.Fill(dtCE) 'Keep data to Datatable
                strID = dtCE.Rows(tempMaxsrvQgate)("ID").ToString
                strPartNo = dtCE.Rows(tempMaxsrvQgate)("PartNo").ToString

                With cmdCE
                    .Connection = conCE
                    .CommandType = CommandType.Text
                    .CommandText = "delete from [Tape] " & _
                                        "Where id = '" & strID & "'and Partno = '" & strPartNo & "' "
                    ' "Where id = '" & strID & "'"
                End With


                cmdCE.ExecuteNonQuery()

                '  End If

                ' Next
                ' MessageBox.Show("Delete Successfully")
            End While
            MessageBox.Show("Delete Successfully")
            ShowData()
            ' conCE.Close()
        Catch exsql As SqlCeException
            MsgBox(exsql.Message, MsgBoxStyle.Exclamation)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-02 18:16:53 By : s_oil_p
 


 

No. 2



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

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

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


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-03 06:48:24 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเกี่ยวกับการ Delete ข้อมูล ของ WinCe code vb.net แต่ Insert และ Update สามารถเพิ่มข้อมูลได้ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่