Janis Peksa

Janis Peksa

  • NA
  • 152
  • 50.7k

Replace doesnt work...

Jul 5 2011 8:29 AM
Hello, I have problem. I'm using OleDbCommand command to do update with replace in it.
Here is my code:

using (OleDbConnection Acces2 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\exports_blaise2\\" + textBox22.Text + ".mdb"))
{
string hmm2 = "UPDATE apsekojums SET telefons = replace(telefons, \";\", \"\")";
using (OleDbCommand cmd2 = new OleDbCommand(hmm2, Acces2))
{
cmd2.CommandType = CommandType.Text;
Acces2.Open();
cmd2.ExecuteNonQuery();
}
Acces2.Close();
}

I'm on Visual C# 2010 and Win XP and Office 2010.
I have added all references etc.
Whan I do update to .mdb files it tells me this: Undefined function 'replace' in expression.
So I google it and found that I can use this:
Microsoft.Office.Interop.Access.Application app = new Microsoft.Office.Interop.Access.Application();
app.DoCmd.SetWarnings(WarningsOn: false);

I tried diffrend ways:
1) app.DoCmd.SetWarnings(WarningsOn: false);
2) app.DoCmd.SetWarnings = false;
3) app.DoCmd.SetWarnings(false);
3) app.DoCmd.SetWarnings(0);

And I got error:
The command or action 'SetWarnings' isn't available now.

Can anyone help me, how can I solve my problem ?

Answers (2)