How to append DB values to a string or arraylist?

G

Guest

Hi

I want to append DB values to a string.

[code

C

string numbers = ""

if(this.phone1.Text != null
numbers += this.phone1.Text + ","

if(this.phone2.Text != null
numbers += this.phone2.Text + ","

string sql = "Select phone from users where userid = 1 or userid = 2 or userid =3 or userid =
System.Data.DataSet ds = SqlHelper.ExecuteDataset(ConnectionString,System.Data.CommandType.Text,sql)
this.numbers.DataSource = ds.Tables[0].DefaultView
this.numbers.DataTextField = "phone"
this.numbers.DataValueField = "userid"
this.numbers.DataBind()

[/code

How can I append those 4 phone values in users table to string numbers which appended the textbox values?

e.g. numbers = 123456,234567,345678,45678

Or, should I use ArrayList to do it? If so, how to write an arraylist for numbers?

Thanks for help
 
N

Nicholas Paldino [.NET/C# MVP]

Tom,

An ArrayList can hold values of any type. If you want, you can cycle
through the DataSet that is returned from the call to Execute on the
SqlHelper class, and then just add the numbers. However, this is really
just duplicating the information that is in the DataSet to begin with, so
you might want to just keep a reference to the data set.

Additionally, you can append the values to a string by just cycling
through the rows, and appending the string representation of the number to
the final string (if you have many rows, then I would suggest using a
StringBuilder for efficiency).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tom said:
Hi,

I want to append DB values to a string.

Code:
C#

string numbers = "";

if(this.phone1.Text != null)
numbers += this.phone1.Text + ",";

if(this.phone2.Text != null)
numbers += this.phone2.Text + ",";

string sql = "Select phone from users where userid = 1 or userid = 2 or userid =3 or userid = 4
System.Data.DataSet ds = SqlHelper.ExecuteDataset(ConnectionString,System.Data.CommandType.Text,sql);
this.numbers.DataSource = ds.Tables[0].DefaultView;
this.numbers.DataTextField = "phone";
this.numbers.DataValueField = "userid";
this.numbers.DataBind();

How can I append those 4 phone values in users table to string numbers
which appended the textbox values?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top