Modifying a dataset value?

G

Guest

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.
 
C

Cowboy \(Gregory A. Beamer\)

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 said:
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.
 
G

Guest

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["Concern_EnteredByID"]
Dim enteredbyname as string = qc2005s.getname(enteredbyid)
ds.Table[0].Row["Concern_EnteredByID"] = enteredbyname

next i

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

Thanx for your help.


Cowboy (Gregory A. Beamer) said:
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 said:
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.
 
G

Guest

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(IFormatProvider 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) said:
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 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top