Solved

Change Column Value In DataSet

Posted on 2004-08-17
2
2,090 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now