Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am reading information from a mysql database into a listbox. The query that i have should only return one column from the database. But when displayed in the listbox that same column is written 4 times. this is my code for the listbox...

 

While myReader.Read()
           'ProgressBar1.Value = ProgressBar1.Value + 5
           ListBox2.Items.Add(myReader.GetString(0) + ":  " + myReader.GetString(1) + ", " + myReader.GetString(2))

       End While

 

Does anyone know why this would display the same thing 4 times???

 

When i run the same query through mysql directly... it comes out right but only when doing it through VB is multiplies

Posted
locationd = My.Settings.location.ToString
       password = My.Settings.password.ToString
       Dim myconnectionString As String
       myconnectionString = "Database=test;Data Source=" + locationd + ";User Id=root;Password=" + password
       Dim mySelectQuery As String = "SELECT guest.id, guest.lastname, guest.firstname FROM guest, student, trans WHERE trans.stid =" + txtBoxID.Text
       Dim myConnection As New MySqlConnection(myconnectionString)
       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()
           'ProgressBar1.Value = ProgressBar1.Value + 5
           ListBox1.Items.Add(myReader.GetString(0) + ":  " + myReader.GetString(1) + ", " + myReader.GetString(2))

       End While
       ' always call Close when done reading.
       myReader.Close()
       ' Close the connection when done with it.
       myConnection.Close()

  • Administrators
Posted

If you cut and paste the contents of the mySelectQuery into your MySQL query tool and run it do you get the correct results?

 

Out of interest what data type is trans.stid in the database?

 

As a final point you could try using a parameterised query rather than string concatenation as it will removed issues due to data type conversions as well as being a more robust / secure solution.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

When i use the query in mySQL directly it produces the right solution... it shows one column.

 

stid is of type integer.

 

How would i go about make that change that you mentioned last?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...