|
-
Jul 9th, 2012, 03:53 PM
#1
Thread Starter
Lively Member
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
-
Jul 9th, 2012, 04:22 PM
#2
Addicted Member
Re: Query for records in a MySQL database
-
Jul 9th, 2012, 04:23 PM
#3
Thread Starter
Lively Member
Re: Query for records in a MySQL database
 Originally Posted by pkarvou
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
-
Jul 9th, 2012, 04:26 PM
#4
Addicted Member
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.
-
Jul 9th, 2012, 04:28 PM
#5
Thread Starter
Lively Member
Re: Query for records in a MySQL database
 Originally Posted by pkarvou
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|