Solved

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

Posted on 2012-04-06
4
199 Views
Last Modified: 2012-05-08
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
Comment
Question by:searchsanjaysharma
  • 2
  • 2
4 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 37815829
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
 

Author Comment

by:searchsanjaysharma
ID: 37885193
ok
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 37885550
is it working? if your question is fully answered, you now need to close it by accepting one of the comments.
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37945388
ok
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now