Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a function that can change the value in a column named MyColumn of Access table MyTable..values in MyColumn's rows that like in MyTextBox1 will be replace with MyTextBox2's text..MyColumn's data type is Text..

how i can write SQL Replace query..

my code is below

OleDbCommand MyQuery = new OleDbCommand("UPDATE MyTable SET MyColumn = REPLACE(MyColumn, '" + MyTextBox1.Text + "','" + MyTextBox2.Text + "')", MyConnection);
Posted
Updated 3-Oct-10 7:00am
v2

If this is throwing an error try -
"UPDATE MyTable SET MyColumn = (Select REPLACE(MyColumn, '" + MyTextBox1.Text + "','" + MyTextBox2.Text + "'))", MyConnection); in line with http://msdn.microsoft.com/en-us/library/ms186862.aspx[^].
 
Share this answer
 
hi
you said "named MyColumn of Access table MyTable.."
are you using Access as your database?
 
Share this answer
 
Comments
Hiren solanki 4-Oct-10 5:08am    
use comments rather then adding another answer having question quality.
it still doesnt work, Abhinav..
yes i am usin Access, Aidin..i want to replace some values in MyColumn..likewise i want to copy the entries that have data in MyColumns that like in MyTextBox3 and replace their data in MyColumn like in MyTextBox4

shall i copy the datagrid rows and update the rows?
 
Share this answer
 
Comments
Hiren solanki 4-Oct-10 5:08am    
use comments rather then adding another answer having question quality.
aidin Tajadod 5-Oct-10 18:31pm    
Hi drago,
Actually Access does not have some sql functions. I asked you because the way you write the query is a little different from sql (and I am not master on access). try replacing the ' with " in answer1. It may help you.
drago mafiacrat 5-Oct-10 19:30pm    
hi Aidin!
u r right..i need the query which writes in Access..for example Replace("Word", "Word", "NewWord")
i tried different methods included the syntax above..but none of them fire the event..i will try again.
by the way u r a master on helping..thank u for ur informing about the problem's solution..i'm grateful for ur care..and u, Abhinav..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900