How to assign the value to combobox when field is of int type.

s = "select distinct id from mststudents where deoflag=0 order by id"
        da = New SqlDataAdapter(s, con)
        dt = New DataTable()

        Dim newCustomersRow As DataRow = dt.NewRow()

        newCustomersRow("id") = "--Select TID--"
        dt.Rows.InsertAt(newCustomersRow, 0)

        With cmbtid

            .DisplayMember = "id"
            .ValueMember = "id"
            .DataSource = dt
        End With

//error comes is Input string was not in a correct format.Couldn't store <--Select TID--> in id Column.  Expected type is Int64.
Who is Participating?
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
you can have your select query return 2 values: an int and a string:

s = "select distinct id, cast(id as varchar) as IDString from mststudents where deoflag=0 order by id"

when you add your dummy value:

        newCustomersRow("IDString") = "--Select TID--"
        newCustomersRow("id") = "0"

and when you set your combo:

            .DisplayMember = "IDString"
searchsanjaysharmaAuthor Commented:
Éric MoreauSenior .Net ConsultantCommented:
is it working? if your question is fully answered, you now need to close it by accepting one of the comments.
searchsanjaysharmaAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.