Solved

Change Column Value In DataSet

Posted on 2004-08-17
2
2,142 Views
Last Modified: 2008-01-09
Hi,

I have a dataset populated by an xml file.

I want to bind more than one column of the dataset to a ListBox DataTextField property.

I cant seem to make that work, so what I am now trying to do is this:

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
   ds.Tables[0].Rows[i].ItemArray.SetValue(ds.Tables[0].Rows[i].ItemArray.GetValue(6).ToString() + " - " + ds.Tables[0].Rows[i].ItemArray.GetValue(7).ToString(), 7);
}

Which is trying to set the value of column 7 to the values of column 6 + " - " + column 7.

After this runs I do the following:
ds.Tables[0].AcceptChanges();
ds.AcceptChanges();


The problem is that when the results are displayed, the value of column 7 has not changed.


Any advice would be much appreciated.

Cheers,
Stew
0
Comment
Question by:stewfidgeon
2 Comments
 
LVL 1

Accepted Solution

by:
chmohan earned 200 total points
ID: 11821131
try
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
  string sTest=ds.Tables[0].Rows[i].[6].ToString  + "-";
 sTest = sTest   + ds.Tables[0].Rows[i].[7].ToString  ;

here you have to use the listbox property to get the column 7 and set the value:)
try this
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistboxobjectcollectionclassindexoftopic.asp


  }

0
 
LVL 3

Expert Comment

by:chintan_vaishya
ID: 11821184
HI,

I think you have a table suppose tablename1.

and columns named columnname1,columnname2,columnname3, etc...

and what you want is you want "Columnname1 - Columnname2" to set as the datasource of the listbox.

I think you can use your query this way........

Select columnname1,columnname2,columnname1 & '-' & columnname2 as Newcolumn from tablename;

I do not remember whether it is & in sql or +.........whatever concatenate your values as a new column in your query.

and then  use that dataset for datasource.

Like,

Listbox1.datasource = ds.Tables[0].Rows[your_column]
or maybe
Listbox1.datasource = ds.Tables[0].Columns[your_column]

Hope this will be useful.
Good Luck.

Chintan.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question