Advertisement
Guest User

ass

a guest
Mar 17th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.06 KB | None | 0 0
  1. Imports MySql.Data.MySqlClient
  2. Imports MySql.Data
  3. Public Class Form1
  4.  
  5.     Dim mycmd As New MySqlCommand
  6.     Dim myconnection As New DTConnection
  7.     Dim objreader As MySqlDataReader
  8.     Dim cmdstr As String
  9.  
  10.     'Dim sort As String = "alter table tbla drop id; alter table tbla auto_increment=1; alter table tbla add id int UNSIGNED NOT NULL auto_increment primary key first;"
  11.  
  12.     Private Sub BTINSERT_Click(sender As Object, e As EventArgs) Handles BTINSERT.Click
  13.         mycmd.Connection = myconnection.open
  14.         mycmd.CommandText = "insert into tbla(fname,username,password) values('" & TNAMES.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "')"
  15.         mycmd.ExecuteNonQuery()
  16.         myconnection.close()
  17.         MsgBox("Data added !!", MsgBoxStyle.Information, "Notice..")
  18.         Dim isi As ListViewItem
  19.         LISTSHOW.Items.Clear()
  20.         mycmd.Connection = myconnection.open
  21.         mycmd.CommandText = "select * from tbla"
  22.         objreader = mycmd.ExecuteReader
  23.         While objreader.Read
  24.             isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  25.             isi.SubItems.Add(objreader.Item("fname").ToString)
  26.             isi.SubItems.Add(objreader.Item("username").ToString)
  27.             isi.SubItems.Add(objreader.Item("password").ToString)
  28.         End While
  29.         myconnection.close()
  30.     End Sub
  31.  
  32.     Private Sub BTUPDATE_Click(sender As Object, e As EventArgs) Handles BTUPDATE.Click
  33.         mycmd.Connection = myconnection.open
  34.         mycmd.CommandText = "update tbla set fname='" & TNAMES.Text & "',username='" & TextBox1.Text & "',password='" & TextBox2.Text & "' where id='" & TID.Text & "'"
  35.         mycmd.ExecuteNonQuery()
  36.         myconnection.close()
  37.         MsgBox("Data changed !!", MsgBoxStyle.Information, "Notice..")
  38.         Dim isi As ListViewItem
  39.         LISTSHOW.Items.Clear()
  40.         mycmd.Connection = myconnection.open
  41.         mycmd.CommandText = "select * from tbla"
  42.         objreader = mycmd.ExecuteReader
  43.         While objreader.Read
  44.             isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  45.             isi.SubItems.Add(objreader.Item("fname").ToString)
  46.             isi.SubItems.Add(objreader.Item("username").ToString)
  47.             isi.SubItems.Add(objreader.Item("password").ToString)
  48.         End While
  49.         myconnection.close()
  50.     End Sub
  51.  
  52.     Private Sub BTDELETE_Click(sender As Object, e As EventArgs) Handles BTDELETE.Click
  53.         mycmd.Connection = myconnection.open
  54.         mycmd.CommandText = "delete from tbla where id='" & TID.Text & "'; alter table tbla drop id; alter table tbla auto_increment=1; alter table tbla add id int UNSIGNED NOT NULL auto_increment primary key first;"
  55.         'mycmd.CommandText = "truncate tbla"
  56.         mycmd.ExecuteNonQuery()
  57.         myconnection.close()
  58.         MsgBox("Data deleted !!", MsgBoxStyle.Information, "Notice..")
  59.         Dim isi As ListViewItem
  60.         LISTSHOW.Items.Clear()
  61.         mycmd.Connection = myconnection.open
  62.         mycmd.CommandText = "select * from tbla"
  63.         objreader = mycmd.ExecuteReader
  64.         While objreader.Read
  65.             isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  66.             isi.SubItems.Add(objreader.Item("fname").ToString)
  67.             isi.SubItems.Add(objreader.Item("username").ToString)
  68.             isi.SubItems.Add(objreader.Item("password").ToString)
  69.         End While
  70.         myconnection.close()
  71.     End Sub
  72.  
  73.     'Private Sub BTSHOW_Click(sender As Object, e As EventArgs) Handles BTSHOW.Click
  74.     '    Dim isi As ListViewItem
  75.     '    LISTSHOW.Items.Clear()
  76.     '    mycmd.Connection = myconnection.open
  77.     '    mycmd.CommandText = "select * from tbla"
  78.     '    objreader = mycmd.ExecuteReader
  79.     '    While objreader.Read
  80.     '        isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  81.     '        isi.SubItems.Add(objreader.Item("fname").ToString)
  82.     '        isi.SubItems.Add(objreader.Item("username").ToString)
  83.     '        isi.SubItems.Add(objreader.Item("password").ToString)
  84.     '    End While
  85.     '    myconnection.close()
  86.     'End Sub
  87.  
  88.     Private Sub LISTSHOW_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LISTSHOW.SelectedIndexChanged
  89.         Dim index As Integer
  90.         If LISTSHOW.SelectedItems.Count = 0 Then Exit Sub
  91.         With LISTSHOW
  92.             index = .SelectedIndices(0)
  93.             TID.Text = .Items(index).Text
  94.             TNAMES.Text = .Items(index).SubItems(1).Text
  95.             TextBox1.Text = .Items(index).SubItems(2).Text
  96.             TextBox2.Text = .Items(index).SubItems(3).Text
  97.         End With
  98.         'Update sub
  99.     End Sub
  100.  
  101.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  102.         Dim isi As ListViewItem
  103.         LISTSHOW.Items.Clear()
  104.         mycmd.Connection = myconnection.open
  105.         mycmd.CommandText = "select * from tbla"
  106.         objreader = mycmd.ExecuteReader
  107.         While objreader.Read
  108.             isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  109.             isi.SubItems.Add(objreader.Item("fname").ToString)
  110.             isi.SubItems.Add(objreader.Item("username").ToString)
  111.             isi.SubItems.Add(objreader.Item("password").ToString)
  112.         End While
  113.         myconnection.close()
  114.     End Sub
  115.  
  116.     Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
  117.         myconnection.open()
  118.         cmdstr = "select * from tbla where fname LIKE '%" & TextBox3.Text & "%';"
  119.  
  120.         mycmd = MySqlCommand(cmdstr, myconnection)
  121.         objreader = mycmd.ExecuteReader
  122.         LISTSHOW.Items.Clear()
  123.         Dim isi As ListViewItem
  124.  
  125.         mycmd.Connection = myconnection.open
  126.         mycmd.CommandText = "select * from tbla"
  127.         objreader = mycmd.ExecuteReader
  128.         While objreader.Read
  129.             isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  130.             isi.SubItems.Add(objreader.Item("fname").ToString)
  131.             isi.SubItems.Add(objreader.Item("username").ToString)
  132.             isi.SubItems.Add(objreader.Item("password").ToString)
  133.         End While
  134.         myconnection.close()
  135.     End Sub
  136.  
  137.  
  138. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement