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



 

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

 



Topic : 094236



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



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



Code สำหรับ Insert สามารถเพิ่มข้อมูลได้
Code (VB.NET)
  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
            ' For i = tempMaxsrvArm To tempMaxsrvQgate
            'i = i + 1

            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()

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


Code สำหรับ Update ไม่สามารถแก้ไขข้อมูลได้
Code (VB.NET)
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 n As Integer
        Dim MAX As Integer
        Try
            MAX = tempMaxsrvQgate + 1
            For i = max To 0 Step -1
                i = i - 1
                ' While (n < 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(i)("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 = "UPDATE Tape SET Func = '" + strFunc + "'  Where id = '" + strID + "',Partno = '" + strPartNo + "'"

                    .CommandText = "UPDATE Tape SET Func = '" + strFunc + "',Handle='" + strHandle + "',Mirror='" + strMirror + "',UserDef1='" + strUserDef1 + "',UserDef2='" + strUserDef2 + "',UserDef3='" + strUserDef3 + "',UserDef4='" + strUserDef4 + "',UserDef5='" + strUserDef5 + "'  Where id = '" + strID + "',Partno = '" + strPartNo + "'"

                End With


                cmdCE.ExecuteNonQuery()

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

สอบถามว่า Code update ต้องแก้ไขไงครับ เพื่อให้ Update ข้อมูลได้
รอบกวนด้วยครับ
ขอบคุณครับ



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







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-04-25 11:50:49 By : s_oil_p View : 896 Reply : 4
 

 

No. 1



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

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

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

Quote:
Where id = '" + strID + "',Partno = '" + strPartNo + "'"


Code (VB.NET)
Where id = '" + strID + "' AND Partno = '" + strPartNo + "'"


ตรง Where น่าจะใช้ AND น่ะครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-04-25 12:45:44 By : mr.win
 


 

No. 2



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



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

ขอบคุณสำหรับคำตอบครับ
เปลี่ยน + เป็น & และ , เป็น &

แต่ผมมีคำถามอีกนิดครับ เดี๋ยวผมมาถามใหม่ครับ


Code (VB.NET)
 .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 & "' "

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-04-25 13:02:00 By : s_oil_p
 

 

No. 3



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

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

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


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-04-25 17:23:09 By : mr.win
 


 

No. 4



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



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

แล้ว Code Delete ต้องทำอย่างไรครับ ตอนนี้งง มากๆ คือว่า ต้องการให้ ข้อมูลในฐานข้อมูลที่อยู่ในโปรแกรม ลบตามข้อมูลใน Server สมมุติว่า ฐานข้อมูลใน Server ก่อนหน้าที่จะลบ มีจำนวน 25 ตัว หลังจากลบแล้วเหลือ 20 ตัว ส่วนในโปรแกรมครั้งแรกมี 25 ตัว ต้องการลบ 5 ตัว เพื่อให้ข้อมูลเท่ากันทั้ง 2 โปรแกรม ต้องทำอย่างไรครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-02 14:51:45 By : s_oil_p
 

   

ค้นหาข้อมูล


   
 

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