I need to run a SQL Query in vb.net to find the average rating for my application. I think this is the correct SQL for doing this:
SELECT AVG(Rating) FROM Feedback;
The only problem is im not sure how to run this query correctly. I had a similar query which I have changed to the following(It doesnt work) and I just wondered if you could help adapt this so it actually works?
Dim conn As New MySqlConnection(DBCred)
Dim sqlquery As String = "SELECT AVG(Rating) FROM Feedback;"
Dim cmd As MySqlCommand
Dim AVGRating As String
conn.Close()
cmd = New MySqlCommand(sqlquery, conn)
conn.Open()
Try
AVGRating = cmd.r
Finally
cmd.Connection.Close()
End Try
conn.Close()
thanks
Chris
try this one.
Link: ADO.NET ExecuteScalar in SqlCommand Object