Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.82 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.         TextBox3.Text = ""
  30.         myconnection.close()
  31.     End Sub
  32.  
  33.     Private Sub BTUPDATE_Click(sender As Object, e As EventArgs) Handles BTUPDATE.Click
  34.         mycmd.Connection = myconnection.open
  35.         mycmd.CommandText = "update tbla set fname='" & TNAMES.Text & "',username='" & TextBox1.Text & "',password='" & TextBox2.Text & "' where id='" & TID.Text & "'"
  36.         mycmd.ExecuteNonQuery()
  37.         myconnection.close()
  38.         MsgBox("Data changed !!", MsgBoxStyle.Information, "Notice..")
  39.         Dim isi As ListViewItem
  40.         LISTSHOW.Items.Clear()
  41.         mycmd.Connection = myconnection.open
  42.         mycmd.CommandText = "select * from tbla"
  43.         objreader = mycmd.ExecuteReader
  44.         While objreader.Read
  45.             isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  46.             isi.SubItems.Add(objreader.Item("fname").ToString)
  47.             isi.SubItems.Add(objreader.Item("username").ToString)
  48.             isi.SubItems.Add(objreader.Item("password").ToString)
  49.         End While
  50.         TextBox3.Text = ""
  51.         myconnection.close()
  52.     End Sub
  53.  
  54.     Private Sub BTDELETE_Click(sender As Object, e As EventArgs) Handles BTDELETE.Click
  55.         mycmd.Connection = myconnection.open
  56.         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;"
  57.         'mycmd.CommandText = "truncate tbla"
  58.         mycmd.ExecuteNonQuery()
  59.         myconnection.close()
  60.         MsgBox("Data deleted !!", MsgBoxStyle.Information, "Notice..")
  61.         Dim isi As ListViewItem
  62.         LISTSHOW.Items.Clear()
  63.         mycmd.Connection = myconnection.open
  64.         mycmd.CommandText = "select * from tbla"
  65.         objreader = mycmd.ExecuteReader
  66.         While objreader.Read
  67.             isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  68.             isi.SubItems.Add(objreader.Item("fname").ToString)
  69.             isi.SubItems.Add(objreader.Item("username").ToString)
  70.             isi.SubItems.Add(objreader.Item("password").ToString)
  71.         End While
  72.         TextBox3.Text = ""
  73.         myconnection.close()
  74.     End Sub
  75.  
  76.     'Private Sub BTSHOW_Click(sender As Object, e As EventArgs) Handles BTSHOW.Click
  77.     '    Dim isi As ListViewItem
  78.     '    LISTSHOW.Items.Clear()
  79.     '    mycmd.Connection = myconnection.open
  80.     '    mycmd.CommandText = "select * from tbla"
  81.     '    objreader = mycmd.ExecuteReader
  82.     '    While objreader.Read
  83.     '        isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  84.     '        isi.SubItems.Add(objreader.Item("fname").ToString)
  85.     '        isi.SubItems.Add(objreader.Item("username").ToString)
  86.     '        isi.SubItems.Add(objreader.Item("password").ToString)
  87.     '    End While
  88.     '    myconnection.close()
  89.     'End Sub
  90.  
  91.     Private Sub LISTSHOW_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LISTSHOW.SelectedIndexChanged
  92.         Dim index As Integer
  93.         If LISTSHOW.SelectedItems.Count = 0 Then Exit Sub
  94.         With LISTSHOW
  95.             index = .SelectedIndices(0)
  96.             TID.Text = .Items(index).Text
  97.             TNAMES.Text = .Items(index).SubItems(1).Text
  98.             TextBox1.Text = .Items(index).SubItems(2).Text
  99.             TextBox2.Text = .Items(index).SubItems(3).Text
  100.         End With
  101.         'Update sub
  102.     End Sub
  103.  
  104.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  105.         Dim isi As ListViewItem
  106.         LISTSHOW.Items.Clear()
  107.         mycmd.Connection = myconnection.open
  108.         mycmd.CommandText = "select * from tbla where fname LIKE '%" & TextBox3.Text & "%' or username LIKE '%" & TextBox3.Text & "%' or password LIKE '%" & TextBox3.Text & "%'"
  109.         objreader = mycmd.ExecuteReader
  110.         While objreader.Read
  111.             isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  112.             isi.SubItems.Add(objreader.Item("fname").ToString)
  113.             isi.SubItems.Add(objreader.Item("username").ToString)
  114.             isi.SubItems.Add(objreader.Item("password").ToString)
  115.         End While
  116.         myconnection.close()
  117.     End Sub
  118.  
  119.     Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
  120.         Form1_Load(Me, New System.EventArgs)
  121.         'myconnection.open()
  122.         'cmdstr = "select * from tbla where fname LIKE '%" & TextBox3.Text & "%';"
  123.  
  124.         'mycmd = MySqlCommand(cmdstr, myconnection)
  125.         'objreader = mycmd.ExecuteReader
  126.         'LISTSHOW.Items.Clear()
  127.         'Dim isi As ListViewItem
  128.  
  129.         'mycmd.Connection = myconnection.open
  130.         'mycmd.CommandText = "select * from tbla"
  131.         'objreader = mycmd.ExecuteReader
  132.         'While objreader.Read
  133.         '    isi = LISTSHOW.Items.Add(objreader.Item("id").ToString)
  134.         '    isi.SubItems.Add(objreader.Item("fname").ToString)
  135.         '    isi.SubItems.Add(objreader.Item("username").ToString)
  136.         '    isi.SubItems.Add(objreader.Item("password").ToString)
  137.         'End While
  138.         'myconnection.close()
  139.     End Sub
  140.  
  141.     Private Sub LISTSHOW_DoubleClick(sender As Object, e As EventArgs) Handles LISTSHOW.DoubleClick
  142.         Form2.Show()
  143.         Dim index As Integer
  144.         If LISTSHOW.SelectedItems.Count = 0 Then Exit Sub
  145.         With LISTSHOW
  146.             index = .SelectedIndices(0)
  147.             Form2.TextBox1.Text = .Items(index).SubItems(1).Text
  148.             Form2.TextBox2.Text = .Items(index).SubItems(2).Text
  149.             Form2.TextBox3.Text = .Items(index).SubItems(3).Text
  150.         End With
  151.     End Sub
  152. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement