Skip to content

Using combobox.selectedvalue in a query

Tania Emmerechts

Asked Oct 13, 2010, 12:04 PM EDT1 answer
Share
LinkedInX
Hello everybody,
I'm just starting to discover C#.
I have a form with a combobox.
This combobox is filled from a database like this :
combobox .SelectedIndex = -1;
combobox .SelectedValue = -1;
combobox .DataSource = sqlDataHelper.DataSet.Tables[0];
combobox .ValueMember = "ShipyardID";
combobox .DisplayMember = "ShipyardName";

When the user makes a choice, this will happen :

object m_shipyardID = combobox .SelectedValue;

Because my Value is an int.
I tried "string m_shipyardID = combobox .SelectedValue;" but that doesn't work.

Now I want to use the m_shipyardID in a query like this :
SELECT * FROM Shipyards WHERE shipyardID = m_shipyardID

But this doesn't work.
Please can somebody help me?
Thanks,
Tania

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Suthish Nair
    0
     
    Welcome Tania,
    i will pefer using Parameterized Query, refer article

    or you can do this way:

    1. object m_shipyardID = Convert.ToInt32(combobox .SelectedValue);

    2. int m_shipyardID = combobox .SelectedValue;

    There are lots of article here, refer those.

     

     
    0