Results 1 to 5 of 5

Thread: Query for records in a MySQL database

  1. #1

    Thread Starter
    Lively Member crazy1993's Avatar
    Join Date
    Sep 2010
    Location
    Rochester, NY
    Posts
    85

    Query for records in a MySQL database

    Hello everyone,

    Alright, so I know there are a lot of threads on mysql and similar things like that but none of them are making any sense to me or are more advanced then I really need to just check if the record exists and save some cells as a variable. Now in PHP this is quite simple for me to do but even with all the pages on here and other places I've looked I haven't found anything that I can understand how to implement.

    I'm using Visual Studio 2010 Professional - vb.net app with .net framework 3.5

    MySQL Connector Net 5.1.7

    --------------------------------

    The following code is php form of what I need to do:

    Code:
    $incomingRNS = $rns; (RNS is passed into the function)
    $result = mysql_query("SELECT * FROM software WHERE RootNS='$incomingRNS'");
    while($row = mysql_fetch_array($result)) {
      $rootpath = $row['RootPath'];
      $specialtext = $row['SpecialText'];
    }
    I'm missing some code to verify (Like check that it only returned one record and to just error if it doesn't)

    I included the PHP code because thats the only way I know how to do what I need. Can anyone help me? I seem to have a VERY VERY hard time grasping certain concepts in coding.

    Thanks!

    Dustin
    ~Dustin Schreiber
    Head Developer for TechJive Dev Team - Founder of http://www.thetechsphere.com
    Who *cares* if a laser guided 500 lb bomb is accurate to within 9 feet?
    Teamwork is essential. It gives the enemy someone else to shoot at.
    Retreating?! Hell no, we're just attacking the other direction!

    Please rate posts if you find them helpful
    <--- Over there genius

  2. #2
    Addicted Member
    Join Date
    Jan 2012
    Location
    Athens, Greece
    Posts
    143

    Re: Query for records in a MySQL database


  3. #3

    Thread Starter
    Lively Member crazy1993's Avatar
    Join Date
    Sep 2010
    Location
    Rochester, NY
    Posts
    85

    Re: Query for records in a MySQL database

    okay, that helps a little with some of the commands but I still am confused on how it works to even get to the point that I can do that.
    ~Dustin Schreiber
    Head Developer for TechJive Dev Team - Founder of http://www.thetechsphere.com
    Who *cares* if a laser guided 500 lb bomb is accurate to within 9 feet?
    Teamwork is essential. It gives the enemy someone else to shoot at.
    Retreating?! Hell no, we're just attacking the other direction!

    Please rate posts if you find them helpful
    <--- Over there genius

  4. #4
    Addicted Member
    Join Date
    Jan 2012
    Location
    Athens, Greece
    Posts
    143

    Re: Query for records in a MySQL database

    Code:
    Public Sub ReadMyData(myConnString As String)
        Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
        Dim myConnection As New MySqlConnection(myConnString)
        Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
        myConnection.Open()
        Dim myReader As MySqlDataReader
        myReader = myCommand.ExecuteReader()
        ' Always call Read before accessing data.
        While myReader.Read()
            Console.WriteLine((myReader.GetInt32(0) & ", " & myReader.GetString(1)))
        End While
        ' always call Close when done reading.
        myReader.Close()
        ' Close the connection when done with it.
        myConnection.Close()
    End Sub 'ReadMyData
    Use this as guide.

    Change the connection and use your query.

    While reading instead of printing with Console.Writeline assign values to your variables.

  5. #5

    Thread Starter
    Lively Member crazy1993's Avatar
    Join Date
    Sep 2010
    Location
    Rochester, NY
    Posts
    85

    Re: Query for records in a MySQL database

    Quote Originally Posted by pkarvou View Post
    Code:
    Public Sub ReadMyData(myConnString As String)
        Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
        Dim myConnection As New MySqlConnection(myConnString)
        Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
        myConnection.Open()
        Dim myReader As MySqlDataReader
        myReader = myCommand.ExecuteReader()
        ' Always call Read before accessing data.
        While myReader.Read()
            Console.WriteLine((myReader.GetInt32(0) & ", " & myReader.GetString(1)))
        End While
        ' always call Close when done reading.
        myReader.Close()
        ' Close the connection when done with it.
        myConnection.Close()
    End Sub 'ReadMyData
    Use this as guide.

    Change the connection and use your query.

    While reading instead of printing with Console.Writeline assign values to your variables.
    Thank you, this seems to make clear up some stuff for me. I'll try it out later when I get back to it.
    ~Dustin Schreiber
    Head Developer for TechJive Dev Team - Founder of http://www.thetechsphere.com
    Who *cares* if a laser guided 500 lb bomb is accurate to within 9 feet?
    Teamwork is essential. It gives the enemy someone else to shoot at.
    Retreating?! Hell no, we're just attacking the other direction!

    Please rate posts if you find them helpful
    <--- Over there genius

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width