I am currently confused and not sure why. I believe I have stared at this for to long. I am currently just trying to populate a ComboBox with the data that is read in from a SQL DB through a SQL query. Currently I have the below code. I am confused as to why I would get the error, " conversion from string "cname" to type 'Integer' is not valid.

 Private Sub QuoteInfo_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'Loads the Existing customers names in the Customer Dropdown

        Mysqlconn = New SqlConnection
        Mysqlconn.ConnectionString = "Server=RTIRAKLAP\SQLEXPRESS;database=GriseDB;Trusted_Connection=yes;"
        Dim READER As SqlDataReader
        Try
            MysqlConn.open()
            Dim Query As String
            Query = "Select * FROM qcust"
            Command = New SqlCommand(Query, Mysqlconn)
            'LEFT OFF SOMETHING WRONG WTIH GETSTRING OR GETTEXTREADER
            READER = Command.ExecuteReader()
            While READER.Read = True
                Dim cName As String = READER.GetString("cname")
                cmbCustomer.Items.Add(cName)
            End While

            MysqlConn.Close()

        Catch ex As SystemException
            MessageBox.Show(ex.Message)
        Finally
            Mysqlconn.Dispose()
        End Try



    End Sub

Well, I think that what this is trying to tell you is that you are supposed to pass the column number (the zero based sequence) into getstring.

Here's the definition of GetString

'Declaration
Public Overrides Function GetString ( _
    i As Integer _
) As String

Edited 2 Years Ago by pritaeas: Fixed link.

so, what will be the possible solution?? how to poplulate the combobox with the specified values in the DB??
I have the same trouble.. any help / guidance will be utmost appreciation.
My code is almost the same as of above.

Edited 2 Years Ago by steve.steins.7

See if this will work for you (I changed lines 9 and 14 below)

Private Sub QuoteInfo_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Loads the Existing customers names in the Customer Dropdown
        Mysqlconn = New SqlConnection
        Mysqlconn.ConnectionString = "Server=RTIRAKLAP\SQLEXPRESS;database=GriseDB;Trusted_Connection=yes;"
        Dim READER As SqlDataReader
        Try
            MysqlConn.open()
            Dim Query As String
            Query = "Select cName FROM qcust"
            Command = New SqlCommand(Query, Mysqlconn)
            'LEFT OFF SOMETHING WRONG WTIH GETSTRING OR GETTEXTREADER
            READER = Command.ExecuteReader()
            While READER.Read = True
                Dim cName As String = READER.GetString(0)
                cmbCustomer.Items.Add(cName)
            End While
            MysqlConn.Close()
        Catch ex As SystemException
            MessageBox.Show(ex.Message)
        Finally
            Mysqlconn.Dispose()
        End Try
    End Sub
This article has been dead for over six months. Start a new discussion instead.