Solved

Change Column Value In DataSet

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

17 Experts available now in Live!

Get 1:1 Help Now