Advertisement
Guest User

Untitled

a guest
Aug 6th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.72 KB | None | 0 0
  1. Imports MySql.Data.MySqlClient
  2. Public Class Form3
  3.     Public listbox3 As New ListBox
  4.     Public splitread() As String
  5.     Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         Dim conn As MySqlConnection
  7.         conn = New MySqlConnection("server=db4free.net;Port=3306; user id=brandonioproduct; password=brandonio; database=brandonioproduct")
  8.         Dim command As New MySqlCommand
  9.         Dim sqlquery As String = "SELECT * FROM NewTable"
  10.         Dim adapter As New MySqlDataAdapter
  11.         Dim data As MySqlDataReader
  12.         conn.Open()
  13.         command.CommandText = sqlquery
  14.         command.Connection = conn
  15.         adapter.SelectCommand = command
  16.         data = command.ExecuteReader
  17.         While data.Read()
  18.             ListBox1.Items.Add(data(3).ToString)
  19.             listbox3.Items.Add(data(0).ToString)
  20.             Dim writer As New System.IO.StreamWriter(My.Application.Info.DirectoryPath + "/" + data(3).ToString + data(0).ToString + ".txt", False)
  21.             writer.Write(data(0).ToString + "=" + data(1).ToString + "=" + data(2).ToString + "=" + data(3).ToString + "=" + data(4).ToString + "=" + data(5).ToString)
  22.             writer.Close()
  23.         End While
  24.  
  25.         data.Close()
  26.         conn.Close()
  27.     End Sub
  28.  
  29.     Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  30.         listbox3.SelectedIndex = ListBox1.SelectedIndex
  31.         Dim reader As New System.IO.StreamReader(My.Application.Info.DirectoryPath + "/" + ListBox1.SelectedItem.ToString + listbox3.SelectedItem.ToString + ".txt")
  32.         splitread = reader.ReadToEnd.Split("=")
  33.         reader.Close()
  34.         lbl_name.Text = "Name : " + splitread(3).ToString
  35.         lbl_password.Text = "Password : " + splitread(2).ToString
  36.         lbl_username.Text = "Username : " + splitread(1).ToString
  37.         lbl_favoritecolor.Text = "Favorite Color : " + splitread(4).ToString
  38.         lbl_favoritefood.Text = "Favorite Food : " + splitread(5).ToString
  39.     End Sub
  40.  
  41.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  42.         If CheckBox1.Checked = True Then
  43.             'Edit mode is enabled
  44.             txt_favoritecolor.Visible = True
  45.             txt_favoritefood.Visible = True
  46.             txt_name.Visible = True
  47.             txt_password.Visible = True
  48.             txt_username.Visible = True
  49.             txt_name.Text = splitread(3).tostring
  50.             txt_password.Text = splitread(2).tostring
  51.             txt_username.Text = splitread(1).tostring
  52.             txt_favoritecolor.Text = splitread(4).tostring
  53.             txt_favoritefood.Text = splitread(5).tostring
  54.             lbl_name.Text = "Name : "
  55.             lbl_password.Text = "Password : "
  56.             lbl_username.Text = "Username : "
  57.             lbl_favoritecolor.Text = "Favorite Color : "
  58.             lbl_favoritefood.Text = "Favorite Food : "
  59.             Button1.Visible = True
  60.  
  61.         Else
  62.             'Edit mode is disabled
  63.             txt_favoritecolor.Visible = False
  64.             txt_favoritefood.Visible = False
  65.             txt_name.Visible = False
  66.             txt_password.Visible = False
  67.             txt_username.Visible = False
  68.             lbl_name.Text = "Name : " + splitread(3).ToString
  69.             lbl_password.Text = "Password : " + splitread(2).ToString
  70.             lbl_username.Text = "Username : " + splitread(1).ToString
  71.             lbl_favoritecolor.Text = "Favorite Color : " + splitread(4).ToString
  72.             lbl_favoritefood.Text = "Favorite Food : " + splitread(5).ToString
  73.             Button1.Visible = False
  74.         End If
  75.     End Sub
  76.  
  77.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  78.         Dim conn As MySqlConnection
  79.         conn = New MySqlConnection("server=db4free.net;Port=3306; user id=brandonioproduct; password=brandonio; database=brandonioproduct")
  80.         Dim command As New MySqlCommand
  81.         Dim sqlquery As String = "UPDATE NewTable SET Username='" & txt_username.Text & "', Password='" & txt_password.Text & "', Name='" & txt_name.Text & "', FavoriteColor='" & txt_favoritecolor.Text & "', FavoriteFood='" & txt_favoritefood.Text & "' WHERE ID='" & listbox3.SelectedItem & "';"
  82.         Dim adapter As New MySqlDataAdapter
  83.         Dim data As MySqlDataReader
  84.         conn.Open()
  85.         command.CommandText = sqlquery
  86.         command.Connection = conn
  87.         adapter.SelectCommand = command
  88.         data = command.ExecuteReader
  89.  
  90.         data.Close()
  91.         conn.Close()
  92.         Me.Close()
  93.         Dim form3 As New Form3
  94.         form3.Show()
  95.     End Sub
  96. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement