473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Modifying a dataset value?

I have a dataset that I want to modify the values in a particular column. I.e
if I have a function to convert the enterbyID (Integer) to a name, in the
dataset the field (Concern_EnteredbyID) shows as the integer. How can I
modifiy the dataset (ds) before I do something else with it?
I've read many posts but without success. Thanx.

Concern_EnteredByID I want (I have the function to pass the
value to)
12 Joe Smith
11 John Smith

Also is there a way to also alter the header info (the ds column name)? Thanx.
Nov 19 '05 #1
3 1677
Non-strongly typed, I assume:

VB.NET
---------
1Can also use ordinal value for table, like ds.Table(0)
ds.Table("TableName").Row(0)("EnteredByID") = 11
ds.Table("TableName").Row(0)("EnteredByName") = "John Smith"

C#
----
//Can also use ordinal value for table, like ds.Table[0]
ds.Table["TableName"].Row[0]["EnteredByID"] = 11;
ds.Table["TableName"].Row[0]["EnteredByName"] = "John Smith";

The biggest issue is finding the correct row. You can, if you desire, run
through the rows:

C#
---
foreach (DataRow dr in ds.Table[0].Rows)
{
if(dr["EnteredByID")==12)
{
dr["EnteredByID"] = 11;
dr["EnteredByName"] = "John Smith";
}
}
Hope this helps.
--
Gregory A. Beamer
MVP; MCP: +I, SD, SE, DBA

*************************************************
Think outside the box!
*************************************************
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...
I have a dataset that I want to modify the values in a particular column. I.e if I have a function to convert the enterbyID (Integer) to a name, in the
dataset the field (Concern_EnteredbyID) shows as the integer. How can I
modifiy the dataset (ds) before I do something else with it?
I've read many posts but without success. Thanx.

Concern_EnteredByID I want (I have the function to pass the
value to)
12 Joe Smith
11 John Smith

Also is there a way to also alter the header info (the ds column name)?

Thanx.
Nov 19 '05 #2
thanx, I'm working in VB.NET so if I had to cycle through all rows modifying
the value of a particular row value/column, what would your C# equiv be? I
need to change the value using it's value.

something like:

for i = 1 to total rowcount(??) ' I assume 1 because the column headers are
the table field names row 0

dim enteredbyid as integer =
ds.Table["TableName"].Row[i]["Concern_EnteredByID"]
Dim enteredbyname as string = qc2005s.getname(enteredbyid)
ds.Table[0].Row[i]["Concern_EnteredByID"] = enteredbyname

next i

'then save/append ds
ds.append ??????????????????

Thanx for your help.
"Cowboy (Gregory A. Beamer)" wrote:
Non-strongly typed, I assume:

VB.NET
---------
1Can also use ordinal value for table, like ds.Table(0)
ds.Table("TableName").Row(0)("EnteredByID") = 11
ds.Table("TableName").Row(0)("EnteredByName") = "John Smith"

C#
----
//Can also use ordinal value for table, like ds.Table[0]
ds.Table["TableName"].Row[0]["EnteredByID"] = 11;
ds.Table["TableName"].Row[0]["EnteredByName"] = "John Smith";

The biggest issue is finding the correct row. You can, if you desire, run
through the rows:

C#
---
foreach (DataRow dr in ds.Table[0].Rows)
{
if(dr["EnteredByID")==12)
{
dr["EnteredByID"] = 11;
dr["EnteredByName"] = "John Smith";
}
}
Hope this helps.
--
Gregory A. Beamer
MVP; MCP: +I, SD, SE, DBA

*************************************************
Think outside the box!
*************************************************
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...
I have a dataset that I want to modify the values in a particular column.

I.e
if I have a function to convert the enterbyID (Integer) to a name, in the
dataset the field (Concern_EnteredbyID) shows as the integer. How can I
modifiy the dataset (ds) before I do something else with it?
I've read many posts but without success. Thanx.

Concern_EnteredByID I want (I have the function to pass the
value to)
12 Joe Smith
11 John Smith

Also is there a way to also alter the header info (the ds column name)?

Thanx.

Nov 19 '05 #3
I can't seem to get this to work, I must be missing something.

I get this Error when I attempt to replace the ID value with the Name.

Error: System.FormatException: Input string was not in a correct format. at
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.String.System.IConvertible.ToInt32(IFormatP rovider provider) at
System.Convert.ToInt32(Object value) at
System.Data.Common.Int32Storage.Set(Int32 record, Object value) at
System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't store in
Concern_EnteredID Column. Expected type is Int32.

Using (and I have tried converting row with no success):

Dim i As Integer
Dim rowcount As Integer = ds.Tables(0).Rows.Count
For i = 0 To rowcount - 1
Dim enteredbyid As Integer =
ds.Tables(0).Rows(i)("Concern_EnteredID")
Dim enteredbyname As String =
qc2005s.GetName(enteredbyid)
Convert.ToString(ds.Tables(0).Columns(2).ToString( ))
ds.Tables(0).Rows(i)("Concern_EnteredID") = enteredbyname
Next i

Thanx for your help.

"Cowboy (Gregory A. Beamer)" wrote:
Non-strongly typed, I assume:

VB.NET
---------
1Can also use ordinal value for table, like ds.Table(0)
ds.Table("TableName").Row(0)("EnteredByID") = 11
ds.Table("TableName").Row(0)("EnteredByName") = "John Smith"

C#
----
//Can also use ordinal value for table, like ds.Table[0]
ds.Table["TableName"].Row[0]["EnteredByID"] = 11;
ds.Table["TableName"].Row[0]["EnteredByName"] = "John Smith";

The biggest issue is finding the correct row. You can, if you desire, run
through the rows:

C#
---
foreach (DataRow dr in ds.Table[0].Rows)
{
if(dr["EnteredByID")==12)
{
dr["EnteredByID"] = 11;
dr["EnteredByName"] = "John Smith";
}
}
Hope this helps.
--
Gregory A. Beamer
MVP; MCP: +I, SD, SE, DBA

*************************************************
Think outside the box!
*************************************************
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...
I have a dataset that I want to modify the values in a particular column.

I.e
if I have a function to convert the enterbyID (Integer) to a name, in the
dataset the field (Concern_EnteredbyID) shows as the integer. How can I
modifiy the dataset (ds) before I do something else with it?
I've read many posts but without success. Thanx.

Concern_EnteredByID I want (I have the function to pass the
value to)
12 Joe Smith
11 John Smith

Also is there a way to also alter the header info (the ds column name)?

Thanx.

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: DraguVaso | last post by:
Hi, Something I don't understand about a Typed DataSet: When a value in the DataSet is DBNull, it throws this error: "Cannot get value because it is DBNull". But aren't Typed DataSets...
3
by: Chris Bingham | last post by:
Hi, I'm learning VB.Net at the moment, and while I'm doing it I'm writing a couple of programs for work! They all work with the same Access Database, but I'm having a problem with modifying...
6
by: JohnR | last post by:
I have a table with 1 row which is used to hold some application wide items (one item per field, hence I only need 1 row). I want to bind one of the fields to a textbox. After setting up the...
4
by: rodchar | last post by:
hey all, i have an Access Database with about 43,000 records in it. I need to take 2 or 3 columns and modify them and update the database. currently what i'm doing is loading all into a...
0
by: BVA3105 | last post by:
i update a database with a dataset and a SqlAdapter with success but when i clear and refill my dataset i always retreive the old values. I have to wait for 5 seconds to get the corrects values. ...
1
by: Trev | last post by:
I would be very grateful if someone could help me with this. I have created a DataSet using Tables.Add(mDataSource), where mDataSource derives from database expressions. However, I now need to...
3
by: benkollam | last post by:
Hi, I have problem updating the changes in the dataset to the database. I am using an Access database and following is the code used for adding a new row. Please help Private Sub...
0
by: davidz | last post by:
My office has adopted Team Foundation Server to track and manage the development and deployment process at our site. I have been asked to modify one of the standard work item reports, "Related...
0
by: rickbear | last post by:
Hi group... I am having big difficulties with dataset and xsd schemas. First I dedicate a specific schema to a dataset. Then I use an adapter to fill each table in the dataset. But the problem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.