0

I have a form in which I am able to list a parent table using datagridview. I also have a child payment table that list all the payments made. I have added a combo box so I can make my search more efficient. Everythhing worked great until I added to box. Now I get this error==

InValidCastException == Conversion from string "" to type 'Double' is not valid.

Can you please helpme correct this?? I am using SQL Server 2005 and Visual Studios 2008.

Dim teamList = From Bowler In Db.Bowlers _ Where Bowler.TeamNumber <> "" _ Order By Bowler.TeamNumber _ Select Bowler.TeamNumber For Each TeamNumber In teamList Me.ToolStripComboBox1.Items.Add(TeamNumber) Next End Sub

Thanks Cheryl

1 Answer 1

2

I assume Bowler.TeamNumber is a Double datatype. This means you cannot do

Bowler.TeamNumber <> ""

instead you can only do

Bowler.TeamNumber <> 0

or

Bowler.TeamNumber <> NULL

EDIT: Following on from comment, you need something like this:

Dim teamList = (From Bowler In Db.Bowlers _ 
Where Bowler.TeamNumber <> "" _ 
Order By Bowler.TeamNumber _ 
Select Bowler.TeamNumber ).Distinct()

For Each TeamNumber In teamList 
Me.ToolStripComboBox1.Items.Add(TeamNumber) 
Next 
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much. I put the "0" everywhere but there.That work great. I can now see the numbers. But, it is now doubling the numbers. There are 4 bowlers per team which means the number "1" will show up 4 times. And it does not populate the grids with info that is in there. Any suggestions. heryl
Thank you. It now only show one number. It is still not populating the tables. Any suggestions?
I git it working.Thanks for your help. Chery Dim bowlerQuery = From Bowler In Db.Bowlers _ Where Bowler.TeamNumber = Me.ToolStripComboBox1.SelectedItem.ToString() _ Select Bowler Me.BowlerBindingSource.DataSource = bowlerQuery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.