Advertisement
hitlerlla

shit

Apr 3rd, 2020
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.11 KB | None | 0 0
  1. ' This is your query string, exactly the same from DAS. Dont tell me you dont know DAS...
  2. ' The only difference is that this query contains '@username' and '@password'
  3. ' These you can say are placeholders for values you are going to put in the future.
  4. ' Nothing more, nothing less. They are just placeholders.
  5. Dim myQuery as String = "SELECT * FROM Accounts WHERE Username = @username AND Password = @password"
  6.  
  7. ' Create a new DataAdapter from the query and the connection, you shouldnt worry about this
  8. ' but if you want to learn more, go read the documentation about this.
  9. da = New OleDb.OleDbDataAdapter(myQuery,con)
  10.  
  11. ' Declare the command, OleDbCommand is special object that deals with the query string for you
  12. ' and does stuff like adding parameters etc. again, if you want to know more, read the docs.
  13. ' myQuery is ur query, con is the OleDbConnection object u made called 'con'
  14. Dim cmd As New OleDbCommand(myQuery, con)
  15.  
  16. ' This part is important. This is what the placeholders exist for, to be replaced.
  17. ' If you take a look into your query above, you can see there are 2 things that start with @
  18. ' followed by some name, i.e @username, @password. You have to tell VB which placeholder
  19. ' you wanna replace with what value.
  20. ' So, basically what this does, is it tries to find the placeholder in the query text (myQuery)
  21. ' that is '@username' and '@password' and replaces it with whatever value is in uservar and passvar,
  22. ' in this case 'uservar' is "John" and 'passvar' is "123"
  23. Dim uservar As String = "John"
  24. Dim passvar As String = "123"
  25. cmd.Params.Add("@username", uservar) ' <- uservar is a string variable, lets say uservar is "John"
  26. cmd.Params.Add("@password", passvar) ' <- passvar is a string variable, lets say passvar is "123"
  27.  
  28. ' Open the connection
  29. con.Open()
  30.  
  31. ' OleDbDataReader is a special object as well, it is special in that it can hold data as well as change the data it holds.
  32. ' you wonder how, i shall tell u now. 'reader' is a OleDbDataReader object.
  33. ' OleDbDataReader object is special cuz the data within it is actually a single row that is returned from
  34. ' the query (myQuery) when ran to your database. So to access a column of this row, you can simply do reader(i),
  35. ' 'i' being the index of the column you want to retrieve data from. Now you're wondering, 'hmm this isnt useful if it only
  36. ' gives me back a single row, what if multiple rows is returned?'
  37. ' Well thats what the '.Read()' function is for. Its quite special in how it works. alotta special thingies here.
  38. ' Basically how it works, whenever the '.Read()' function is called, in this case 'reader.Read()',
  39. ' The function will either return a 'True' or a 'False' depending on if there is another row after the current row.
  40. ' If it is 'True', the data within OleDbDataReader object, in this case 'reader', will get replaced with the data in the next row.
  41. ' So reader will have a whole new set of data within it.
  42. Dim reader As OleDbDataReader = cmd.ExecuteReader()
  43.  
  44. ' Put it in a loop to keep reading for rows.
  45. While reader.Read()
  46.     ' Opens a messagebox to show the 2nd column for each row returned.
  47.     MsgBox(reader.GetString(1))
  48. End While
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement