Hello Gurus,
With Visual Basic and SQL, I am trying to populate a Chart using a connection to my SQL Database. Each time I run it I get this error "Conversion from string to type integer is not valid".
I do not see anywhere in my code where it is attempting to convert any of the data types which leads to my confusion.
Would somebody mind taking a look please ?? - All variables have been declared previously in the Public Class -
=======================================================================================
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Try
If con.State = ConnectionState.Open Then
con.Close()
con.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\my_name\Documents\Visual Studio 2012\Projects\Expense Management Solutions\Expense Management Solutions\VBConnectionFinal.mdf;Integrated Security=True"
End If
con.Open()
Dim Query As VariantType
Query = "select * from Table_1"
cmd = New SqlCommand(Query, con)
Dim dr As SqlClient.SqlDataReader
dr = cmd.ExecuteReader()
While dr.Read
Chart1.Series("NAME_vs_AGE").Points.AddXY(dr.GetString("name"), dr.GetInt32("age"))
End While
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
con.Dispose()
End Try
End Sub
=================================================================================
Thanks in advance !!
jagrenet
With Visual Basic and SQL, I am trying to populate a Chart using a connection to my SQL Database. Each time I run it I get this error "Conversion from string to type integer is not valid".
I do not see anywhere in my code where it is attempting to convert any of the data types which leads to my confusion.
Would somebody mind taking a look please ?? - All variables have been declared previously in the Public Class -
=======================================================================================
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Try
If con.State = ConnectionState.Open Then
con.Close()
con.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\my_name\Documents\Visual Studio 2012\Projects\Expense Management Solutions\Expense Management Solutions\VBConnectionFinal.mdf;Integrated Security=True"
End If
con.Open()
Dim Query As VariantType
Query = "select * from Table_1"
cmd = New SqlCommand(Query, con)
Dim dr As SqlClient.SqlDataReader
dr = cmd.ExecuteReader()
While dr.Read
Chart1.Series("NAME_vs_AGE").Points.AddXY(dr.GetString("name"), dr.GetInt32("age"))
End While
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
con.Dispose()
End Try
End Sub
=================================================================================
Thanks in advance !!
jagrenet