• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

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()
        da.Fill(dt)

        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
        cmbtid.Refresh()



//error comes is Input string was not in a correct format.Couldn't store <--Select TID--> in id Column.  Expected type is Int64.
0
searchsanjaysharma
Asked:
searchsanjaysharma
  • 2
  • 2
1 Solution
 
Éric MoreauSenior .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"
0
 
searchsanjaysharmaAuthor Commented:
ok
0
 
É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.
0
 
searchsanjaysharmaAuthor Commented:
ok
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now