Hi Guys,
I have some problems in spiting a composite cell value and adding them into a list box.Can you please let me know how i can do it?

I have a code like below which is suppose to return a Primary Key cell value.the code works fine and return every single cell value for primary key but in some cases which the cell value is a composite value like[UnitCode,ID,Area] the value will add to list box just as ONE Item like UnitCode,ID,Area.

using (OracleConnection oraConnection = new OracleConnection())
            {
                oraConnection.ConnectionString = GenerateConnectionString();
                oraConnection.Open();
                OracleCommand oc = new OracleCommand(cmdPK, oraConnection);
                OracleDataReader reader = oc.ExecuteReader();
                try
                {
                     while (reader.Read())
                    {
                       lstPK.Items.Add(reader[0]);
                    }
                }
                catch (Exception ex)
                {
                    lblCon.Text = ex.Message;
                }

Can you please let me know how I can split the value in a cell and add them to a list box like three separate items?
Thanks for you time

Recommended Answers

All 3 Replies

you are getting a string as the result, so all you have to do is split the reaulst and them add it to the list.

to split the result use the split(',') function; that will give you an array which then you can add to the list box,

Try splitting it(as said in the post abouve with th Split method.
And do it like:

while (reader.Read())
            {
                string[] array = reader[0].ToString().Split(',');
                foreach (string item in array)
                    lstPK.Items.Add(item);
            }

Even if there will be no comma in the string, there will always be one item to add to listBox.

Thanks Mitja,
You are a Rock!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.