Solved

Change Column Value In DataSet

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET 5 Templates 2 79
Service Controller 1 23
What can cause the styling on a .NET site to not be found? 17 26
HTML - Color not displaying correctly in EMAIL. 6 41
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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!
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

823 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