อยากทราบวิธีการเปลียน string ให้เป็น Integer ใน visual studio 2010 ค่ะ

คืออยากให้ค่าที่บันทึก ใน array ที่ listview เปลี่ยน จาก string เป็น Integer เพื่อให้เวลากดบันทึกข้อมูลแล้วตัวเลขไปอัพเดตที่ ช่องคงเหลือ อ่ะคะ
Imports System.Data.SqlClient
Public Class Form1

    Public Sub open_database()
        If cn.State = ConnectionState.Closed Then cn.Open()
        Dim jumjim As String

    End Sub
    Private Sub searching()
        sql = String.Format("select Item,product_name,Lot_number,unit,supplier_no,location from tbl_head where product_name like '%{0}%' or lot_number like '%{0}%' or Item like '%{0}%'", txt_search.Text)
        datagrid_search.DataSource = cmd_dataTable()


    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_search.TextChanged
        searching()
    End Sub


    Private Sub bnt_search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnt_search.Click
        searching()
    End Sub


    'ไม่ต้องเปลี่ยนภาษาก็ได้

    Public Function change_barcode(ByVal barcode As String) As String
        Dim result As String = ""
        For Each c As Char In barcode
            Select Case c
                Case "ๅ" : result &= "1"
                Case "/" : result &= "2"
                Case "-" : result &= "3"
                Case "ภ" : result &= "4"
                Case "ถ" : result &= "5"
                Case "ุ" : result &= "6"
                Case "ึ" : result &= "7"
                Case "ค" : result &= "8"
                Case "ต" : result &= "9"
                Case "จ" : result &= "0"
                Case Else : result &= c
            End Select


        Next

        Return result


    End Function


    Private Sub txt_barcode_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt_barcode.KeyDown


        'บอกว่าหลังจากยิงบาร์โค้ดต้องกดเอ็นเตอร์
        If e.KeyData = Keys.Enter Then

            If txt_barcode.Text = "*" Then
                txt_amount.Text = ""
                txt_amount.Select()
                Return
            End If


            Dim old_barcode As String = txt_barcode.Text
            Dim new_barcode As String = change_barcode(old_barcode)

            sql = "select * from tbl_head where barcode_number='" & new_barcode & "'"
            Dim dts As DataTable = cmd_excuteToDataTable()
            If dts.Rows.Count <= 0 Then
                MsgBox("ไม่พบรหัสสินค้า")
                Return
            End If
            'บอกว่า ใน lbl นั้นๆ แสดงอะไรใน ฐานข้อมูล
            lbl_productname.Text = dts.Rows(0)("item")
            lbl_lotnumber.Text = dts.Rows(0)("lot_number")
            lbl_suppliername.Text = dts.Rows(0)("supplier_no")




            'เวลายิงให้ไปหาว่ามีตัวนี้อยู่แล้วไหม ถ้ามีก็ให้ไปรวมกัน
            Dim research As ListViewItem = ListView1.FindItemWithText(new_barcode)
            'ไปเช็คว่า อันไหนไม่ใช่สตริง
            If ListView1.Items.Count = 0 Then

                Dim arr(11) As String
                arr(0) = ListView1.Items.Count + 1
                arr(1) = dts.Rows(0)("Item")
                arr(2) = dts.Rows(0)("product_name")
                arr(3) = dts.Rows(0)("lot_number")
                arr(4) = dts.Rows(0)("unit")
                arr(5) = dts.Rows(0)("supplier_no")
                arr(6) = dts.Rows(0)("location")
                arr(7) = txt_amount.Text
                arr(8) = dts.Rows(0)("amount")
                arr(9) = arr(7) * arr(8)
                arr(10) = dts.Rows(0)("remain")
                arr(11) = dts.Rows(0)("barcode_number")

                Dim itm As New ListViewItem(arr)
                ListView1.Items.Add(itm)


            ElseIf research.Index < 0 Then

                Dim arr(11) As String
                arr(0) = ListView1.Items.Count + 1
                arr(1) = dts.Rows(0)("Item")
                arr(2) = dts.Rows(0)("product_name")
                arr(3) = dts.Rows(0)("lot_number")
                arr(4) = dts.Rows(0)("unit")
                arr(5) = dts.Rows(0)("supplier_no")
                arr(6) = dts.Rows(0)("location")
                arr(7) = txt_amount.Text
                arr(8) = dts.Rows(0)("amount")
                arr(9) = arr(7) * arr(8)
                arr(10) = dts.Rows(0)("remain")
                arr(11) = dts.Rows(0)("barcode_number")
                Dim itm As New ListViewItem(arr)
                ListView1.Items.Add(itm)

            Else
                Dim old_amount As Integer = ListView1.Items(research.Index).SubItems(7).Text
                Dim new_amount As Integer = old_amount + txt_amount.Text

                Dim count As Integer = ListView1.Items(research.Index).SubItems(8).Text

                ListView1.Items(research.Index).SubItems(7).Text = new_amount
                ListView1.Items(research.Index).SubItems(9).Text = count * new_amount




            End If


            txt_barcode.Text = ""
            txt_barcode.Select()
            txt_total.Text = FormatNumber(total_product)
            txt_amount.Text = "1"

        End If
    End Sub

    'รวมจำนวนสินค้า
    Private Function total_product()
        Dim i As Integer = ListView1.Items.Count - 1
        Dim total As Integer = 0
        For j As Integer = 0 To i
            total += ListView1.Items(j).SubItems(9).Text


        Next
        Return total
    End Function







    Private Sub txt_amount_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyData = Keys.Enter Then
            txt_barcode.Text = ""
            txt_barcode.Select()

        End If
    End Sub




    Private Sub bnt_save1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnt_save1.Click
        open_database()

        
        Dim jumjim As String
    
        jumjim = "update tbl_head set remain = remain+" & total_product() & "where barcode_number='"

        cmd = New SqlCommand(sql, cn)
        If cmd.ExecuteNonQuery = 0 Then
            MsgBox("ผิดพลาด")
        Else
            MsgBox("สำเร็จ")

        End If



    End Sub
End Class

ขอบคุณล่วงหน้าด้วยนะคะ
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่