Guest User

Untitled

a guest
Jul 11th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.64 KB | None | 0 0
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Try
  3.             Dim conn As New MySqlConnection
  4.             conn.ConnectionString = "server =localhost;user = root;password =1; database = pof"
  5.             Try
  6.                 conn.Open()
  7.             Catch ex As MySqlException
  8.                 MsgBox("Error", MsgBoxStyle.Exclamation)
  9.             End Try
  10.             Dim myCOmmand As New MySqlCommand
  11.             Dim myReader As MySqlDataReader
  12.             myCOmmand = New MySqlCommand
  13.             myCOmmand.Connection = conn
  14.             myCOmmand.CommandText = "select * from iteminfo where item_code = '" + TextBox1.Text + "';"
  15.             myReader = myCOmmand.ExecuteReader
  16.             If myReader.Read Then
  17.                 dayaCode.Text = myReader(0)
  18.                 dayaName.Text = myReader(1)
  19.                 dayaQty.Text = myReader(2)
  20.                 dayaPresyo.Text = myReader(3)
  21.             Else
  22.                 MsgBox("No Available Product for the Item Code !", MsgBoxStyle.Exclamation, "")
  23.             End If
  24.             With myCOmmand
  25.                 .CommandText = "Insert into transaction values('" & Me.dayaCode.Text & _
  26.                                   "','" & Me.dayaName.Text & "'," & Val(Me.dayaQty.Text) & _
  27.                                  "," & Val(Me.dayaPresyo.Text) & ",'" & Me.TextBox1.Text & "');"
  28.             End With
  29.             ShowMe("select item_code,item_name,item_quantity,item_price from transaction where item_code='" & Me.dayaCode.Text & "'")
  30.         Catch ex As Exception
  31.             MessageBox.Show(ex.Message)
  32.         End Try
  33.     End Sub
  34.     Public Sub ShowMe(ByVal statement As String)
  35.         mycommand = New MySqlCommand
  36.         Try
  37.             connect()
  38.             mycon.Open()
  39.             With mycommand
  40.                 .CommandText = statement
  41.                 .Connection = mycon
  42.                 myreader = .ExecuteReader
  43.             End With
  44.             Me.ListView1.Items.Clear()
  45.             Do While myreader.Read
  46.                 Dim ShowMe As New ListViewItem(myreader.Item("item_code").ToString)
  47.                 ShowMe.SubItems.Add(myreader.Item("item_name").ToString)
  48.                 ShowMe.SubItems.Add(myreader.Item("item_quantity").ToString)
  49.                 ShowMe.SubItems.Add(myreader.Item("item_price").ToString)
  50.                 Me.ListView1.Items.Add(ShowMe)
  51.                 Me.ListView1.Refresh()
  52.             Loop
  53.         Catch ex As Exception
  54.             MessageBox.Show(ex.Message)
  55.         Finally
  56.             mycon.Close()
  57.             myreader.Close()
  58.             mycommand.Dispose()
  59.             End Try
  60.  
  61.     End Sub
Add Comment
Please, Sign In to add comment