CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010
    Posts
    10

    [RESOLVED] Replace doesnt work...

    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 ?

  2. #2
    Join Date
    Nov 2010
    Posts
    10

    Re: Replace doesnt work...

    Found solution:

    Code:
    UPDATE table SET MyColumName = MID(MyColumName, 1, INSTR(MyColumName, ';') - 1) + '' + MID(MyColumName, INSTR(MyColumName, ';') + LEN(';'), LEN(MyColumName) - INSTR(MyColumName, ';') - LEN(';') + 1) WHERE INSTR(MyColumName, ';') > 0;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured