Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

list box empty not shown data

$
0
0

Dear All,
 
i am using vs2008 and sql database.
i have a combobox in which there are two option : gold and silver
when i am select the silver value then its show the silver value from the database and if i am select the gold then its show the gold value from the database.
but its not working.
 
DAtabase :RPSJDB
Table Name: ItemTable
Column Name: txtItemId(pk,int,NotNull)
cmbItemType(nvarcha(50),not Null)
txtItemCode(nvarcha(50),not Null)
txtItemDescription(nvarcha(50),not Null)
txtLaborCharge(float,Null)
txtItemPercent(float,Null)
 
when itemType=Gold then all the Itemdescription = show in list box
 

all the coding is working fine without any error.so pls tell me what is the problem in my code.
 

<div style="display: block;" id="premain0" class="pre-action-link" width="100%"> Collapse |Copy Code</div>
privatevoid 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 Distinct * FROM ItemTable", conn);//SqlCommand cmd = new SqlCommand("SELECT DISTINCT cmbItemType 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";this.cmbItemType.ValueMember = "Value";
            ItemHaveBeenAdded = true;						
        }publicclass AddValue
        {privatestring Displaym;privatelong Valm;public AddValue(string Display,long Value)
            {
                Displaym = Display;
                Valm = Value;
            }publicstring Display
            {get { return Displaym; }
            }publiclong Value
            {get { return Valm; }
            }
        }privatevoid cmbItemType_SelectedIndexChanged(object sender, EventArgs e)
        {if (this.ItemHaveBeenAdded)
            lstboxItem();
        }privatevoid lstboxItem()
        {string connstr = @"Server=.\SQLEXPRESS ;Initial Catalog=RPSJDB;Integrated Security=True; Max Pool Size=100";
            SqlConnection conn = new SqlConnection(connstr);this.lstbItemDescription.Items.Clear();
            SqlCommand cmd = new SqlCommand
                ("SELECT cmbItemType FROM ItemTable Where cmbItemType ="+ cmbItemType.SelectedValue, conn);
            conn.Open();
            SqlDataReader sdrItem = cmd.ExecuteReader();while (sdrItem.Read())
            {this.lstbItemDescription.Items.Add(sdrItem.GetString(1));
            }
            sdrItem.Close();
            conn.Close();
        }privatevoid button1_Click(object sender, EventArgs e)
        {this.Close();
        }

Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>