how to search/replace items in specific column of a datatable

T

TB

Before displaying the result of a table called "people" in a datagrid
called "mydatagrid", I need to modify the content of a column called
"moreinfo" in the in-memory datatable (but not the corresponding table
of the database).

I was thinking of doing something like this:

Dim strSQL as string = "Select ID, firstname, lastname, moreinfo from
people order by lastname"
Dim myConnection As MySqlConnection = New
MySqlConnection(connectionstring)
Dim myDataAdapter As MySqlDataAdapter = New MySqlDataAdapter(strSQL,
myConnection)
Dim myDataSet As DataSet = new Dataset
Dim row As DataRow
Dim searchstring as string = "colour"
Dim replacestring as string = "color"
myDataAdapter.Fill(mydataset, "mytable")
For Each row In myDataSet.Tables("tbl").Rows
Replace(row("moreinfo"), searchstring, replacestring)
Next

mydatagrid.DataSource = myDataSet.Tables("tbl") 'datagrid previously
defined
mydatagrid.DataBind()

However when the datagrid is displayed, no replace action seems to have
taken place, as the original data (including the word "colour") of the
"moreinfo" column of the "people" table is displayed instead.

What am I doing wrong here?

Thanks

TB
 
G

Guest

Hi TB,

It should be

For Each row In myDataSet.Tables("tbl").Rows
row("moreinfo") = row("moreinfo").ToString.Replace(searchstring,
replacestring)
Next


HTH

Elton Wang
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top