473,320 Members | 1,958 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,320 software developers and data experts.

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

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

Feb 26 '06 #1
2 2140
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

"TB" wrote:
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

Feb 26 '06 #2
TB
Of course!

Thanks a lot.

TB

Feb 26 '06 #3

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

Similar topics

4
by: Jane Doe | last post by:
Hi, I need to search and replace patterns in web pages, but I can't find a way even after reading the ad hoc chapter in New Rider's "Inside JavaScript". Here's what I want to do: function...
14
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like...
2
by: Ryan | last post by:
I'm looking for a stored procedure (or query) to search an entire database for a specific string value and replace it with another. I'm sure I saw an SP for this a while back by someone, but cannot...
6
by: DraguVaso | last post by:
Hi, I have a ComboBox of +- 15.000 items in it, via a DataSource. On Top of the Items-list, I want to add some values, based on a user choise (via a filter on the DataSource). Does anybody know...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
4
by: Terry | last post by:
Hi, I am both new to .Net (coming from VB6 and DAO) and to this news group. I am trying to convert some code from VB6 that uses a "record set" to help the user locate a specific record. As the...
4
by: Rich | last post by:
Hello, I need to store various values that I will need to look up later on. I have been using hashtables and arraylists. But I can only store 2 items per row in a hashtable - key, value, and...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.