I'm having a problem with Dim query As New MySqlCommand("Select count(*)....") I would like to take the variable query and do an If query <> 1 Then statement on it. Is this possible or is there a completely other way to go about this comparing the contents of a MySQL select statement. I'm rather new to Visual Basic. 
            Asked
            
        
        
            Active
            
        
            Viewed 215 times
        
    0
            
            
         
    
    
        Joel Coehoorn
        
- 399,467
- 113
- 570
- 794
 
    
    
        Marc Brigham
        
- 2,114
- 5
- 22
- 27
1 Answers
0
            The MySqlCommand type doesn't return the results after construction, it just creates an object that can run queries. You must then execute the query:
Dim result as Integer
Using cn As New MySqlConnection("your connection string here"), _
      cmd As New MySqlCommand("Select count(*) ...", cn)
    cn.Open()
    result = CInt(cmd.ExecuteScalar())
End Using
Don't forget to use query parameters rather than string concatenation to substitute data into your sql statements.
 
    
    
        Community
        
- 1
- 1
 
    
    
        Joel Coehoorn
        
- 399,467
- 113
- 570
- 794