Dear All,
I want tocreate a selection list itemwhen I am select the gold itemthen show only gold item
in the list and
when I m select the silver item
then it show the only silver item in the list box.
I am using following code but it gives a error “conversion faild
when converting the nvarchar value ‘Gold’
to data type int.” so what
is the problem in my code.
private void cmboItemType() //for combobox { string connstr = @"Server=.\SQLEXPRESS ;Initial Catalog=RPSJDB;Integrated Security=True; Max Pool Size=100"; SqlConnection conn = new SqlConnection(connstr); SqlCommand cmd = new SqlCommand("SELECT * FROM ItemTable", conn); conn.Open(); SqlDataReader sdr = cmd.ExecuteReader(); ArrayList ItemStore = new ArrayList(); while (sdr.Read()) { ItemStore.Add(new AddValue(sdr.GetString(1), sdr.GetInt32(0))); } sdr.Close(); conn.Close(); cmbItemType.DataSource = ItemStore; cmbItemType.DisplayMember = "Display"; cmbItemType.ValueMember = "Value"; ItemHaveBeenAdded = true; } private void lstboxItem() //for listbox { string connstr = @"Server=.\SQLEXPRESS ;Initial Catalog=RPSJDB;Integrated Security=True; Max Pool Size=100"; SqlConnection conn = new SqlConnection(connstr); this.lstbItem.Items.Clear(); SqlCommand cmd = new SqlCommand ("SELECT * FROM ItemTable Where cmbItemType =" + cmbItemType.SelectedValue, conn); conn.Open(); SqlDataReader sdrItem = cmd.ExecuteReader(); while (sdrItem.Read()) { this.lstbItem.Items.Add(sdrItem.GetString(1)); } sdrItem.Close(); conn.Close(); } private void cmbItemType_SelectedIndexChanged(object sender, EventArgs e) { if (this.ItemHaveBeenAdded) lstboxItem(); } public class AddValue { private string Displaym; private long Valm; public AddValue(string Display, long Value) { Displaym = Display; Valm = Value; } public string Display { get { return Displaym; } } public long Value { get { return Valm; } } }