Advertisement
Guest User

Untitled

a guest
Oct 4th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.  
  3.     Dim maxrows As Integer
  4.     Dim counter As Integer
  5.  
  6.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  7.  
  8.         'the following procedures will run when the form is loaded
  9.  
  10.         ConnectToDatabase("SELECT * FROM tblUser", "tblUser")
  11.         FillListBoxes("tblUser")
  12.  
  13.  
  14.     End Sub
  15.  
  16.     Sub FillListBoxes(ByVal strTable As String)
  17.  
  18.         lbx_username.Items.Clear()
  19.         lbx_password.Items.Clear()
  20.         lbx_level.Items.Clear()
  21.  
  22.         maxrows = ds.Tables(strTable).Rows.Count
  23.  
  24.         For counter = 0 To (maxrows - 1)
  25.  
  26.             lbx_username.Items.Add(ds.Tables(strTable).Rows(counter).Item(1))
  27.             lbx_password.Items.Add(ds.Tables(strTable).Rows(counter).Item(2))
  28.             lbx_level.Items.Add(ds.Tables(strTable).Rows(counter).Item(3))
  29.  
  30.         Next
  31.  
  32.     End Sub
  33.  
  34.  
  35.     Private Sub Btn_Save_Click(sender As Object, e As EventArgs) Handles btn_Save.Click
  36.  
  37.         Dim cb As New OleDb.OleDbCommandBuilder(da)
  38.         Dim dsNewRow As DataRow
  39.  
  40.         dsNewRow = ds.Tables("tblUser").NewRow()
  41.  
  42.         dsNewRow.Item(1) = txt_NewUsername.Text
  43.         dsNewRow.Item(2) = txtx_NewPassword.Text
  44.         dsNewRow.Item(3) = txt_NewLevel.Text
  45.  
  46.         'new row is now added to the dataset table but it is NOT yet saved to the Actual Acceess Database
  47.        ds.Tables("tblUser").Rows.Add(dsNewRow)
  48.  
  49.         'this line now saves the dataset to the actual Access database. The data adapter is updated
  50.  
  51.         'something wrong with this line... apparently!!
  52.        da.Update(ds, "tblUser")
  53.  
  54.         FillListBoxes("tblUser")
  55.  
  56.         MsgBox("New User Information Has Been Saved")
  57.  
  58.     End Sub
  59.  
  60.     Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
  61.  
  62.         con.Close()
  63.  
  64.     End Sub
  65.  
  66.     Private Sub Btn_Search_Click(sender As Object, e As EventArgs) Handles btn_Search.Click
  67.  
  68.         Dim required As Char
  69.         Dim position As Integer
  70.         Dim current As String
  71.         Dim match As Boolean
  72.  
  73.         txt_ShowUsername.Clear()
  74.         txt_ShowPassword.Clear()
  75.         txt_ShowLevel.Clear()
  76.  
  77.         match = False
  78.         maxrows = ds.Tables("tblUser").Rows.Count
  79.  
  80.         required = txt_RequiredLevel.Text
  81.  
  82.         For position = 0 To (maxrows - 1)
  83.             current = ds.Tables("tblUser").Rows(position).Item(3)
  84.             If current = required Then
  85.                 match = True
  86.                 txt_ShowUsername.Text = ds.Tables("tblUser").Rows(position).Item(1)
  87.                 txt_ShowPassword.Text = ds.Tables("tblUser").Rows(position).Item(2)
  88.                 txt_ShowLevel.Text = ds.Tables("tblUser").Rows(position).Item(3)
  89.                 MsgBox("Look For Another Match")
  90.             End If
  91.         Next
  92.  
  93.         If match = False Then
  94.             MsgBox("Sorry, No Users Have That Level Of Access")
  95.         Else
  96.             MsgBox("No More Records")
  97.         End If
  98.  
  99.         txt_RequiredLevel.Clear()
  100.  
  101.     End Sub
  102. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement