1

I am a newbie in vb.net so I don't know how to do with this, I was trying to display the sum of the counted rows of a table from my database and it will be displayed in a textbox but after the execution it didn't show in the textbox, I don't know where I've got it wrong even though it doesn't have an error.

so far this is my code:

connect.Open()
    da = New MySqlDataAdapter("Select * from tbl_book_info", connect)
    Dim row As String
    row = "Select count(ISBN) from tbl_book_info"
    cmd = New MySqlCommand(row, connect)
    READER = cmd.ExecuteReader
    Dim count As Integer = 0
    For Each rowcount As DataTable In dataset.Tables
        count += rowcount.Rows.Count()
        TextBox7.Text = count.ToString
    Next
    connect.Close()

thank you in advance :)

4
  • 2
    There are many issues at hand here, not just one. You need to call .Read on your reader for example, otherwise you will not read anything. No need to loop either as you should only return a scalar value that is your count... Make sure to Dispose of your objects as well, don't leave them in the yard... Where is dataset.Tables coming from; you are not Filling one in which you would do from a DataAdapter? As you can see there are many issues, that is just a few of them. I would honestly start over and work your way down. Commented Mar 2, 2017 at 16:07
  • That DataAdapter is not used, If you usd cmd.ExecuteScalar(); for the Count query., it will return the number of rows. No loop on something else needed. Commented Mar 2, 2017 at 16:11
  • The dupe link provides a more complete/better answer Commented Mar 2, 2017 at 16:51
  • @Plutonix is correct, but the link he posted is for SQL not MySQL. In this case just replace the SQL parts with the MySQL equivalent. Commented Mar 2, 2017 at 17:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.