0

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

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Behseini
Featured Replies
  • Try splitting it(as said in the post abouve with th Split method. And do it like: [CODE] while (reader.Read()) { string[] array = reader[0].ToString().Split(','); foreach (string item in array) lstPK.Items.Add(item); } [/CODE] Even if there will be no comma in the string, there will always be one item to add … Read More

0

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,

1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.