?
Solved

Change Column Value In DataSet

Posted on 2004-08-17
2
Medium Priority
?
2,241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
chmohan earned 800 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 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