Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi morning

From the Yesterdays evening i am try to Achieve My Requirement,

it was the small thing but it was Creating the problem

so let me explain the problem,


i want to replace Function in the update query to msacess Database(2003),
this was I had tried so please see that and say where i am Going wrong
it was showing Error as the "Undefined function Replace In the statement"

update addcust set grou=Replace(grou, '" + comboBox1.SelectedItem.ToString() + "', '" + comboBox2.SelectedItem.ToString() + "') where id=" + saaa[i] + "


this is the query i am using
here grou and id is the columnNames
addcust is the table Name

please show the rightway to me , thankq alot;
Posted
Updated 29-Sep-11 22:22pm
v2
Comments
Bala Selvanayagam 30-Sep-11 4:16am    
What version of access you are using 2000/2003 or 2007 ?
[no name] 30-Sep-11 4:21am    
2003

Bala Selvanayagam 1-Oct-11 7:50am    
let me know whether the solution i have posted works for you ?

I think replace() function does not work outside the MS Access environment. check the following link for some of the options:

http://www.tek-tips.com/viewthread.cfm?qid=926348&page=485[^]
 
Share this answer
 
Hi, I have no clue why you are using that Replace but an update statement is fairly basic and could look something like:

C#
String updateQuery = @"UPDATE addcust SET grou='" + comboBox1.SelectedItem.ToString() + "' WHERE id=" + saaa[i] + ";";


For a much complex tutorial on this, please go here:
http://office.microsoft.com/en-us/access-help/update-data-by-using-a-query-HA010076527.aspx[^]

Hope that helps,
Morgs
 
Share this answer
 
Comments
[no name] 30-Sep-11 4:19am    
i had a situtation to replace the string in the Updatestatement
Morgs Morgan 30-Sep-11 4:35am    
But does the above solution resolves your problem? To replace a string you would for instance say:
comboBox1.SelectedItem.ToString().Replace("a", "b");

Let me know if this problem is now resolved.
I am afraid the replace statement does not support MS access environment as stated by "Om Prakash Pant" and suggest the followings code - you may have to do bit of cleaning

try
  {

      OleDbConnection oConn = new OleDbConnection();
      oConn.ConnectionString ="Provider =Microsoft.Jet.OLEDB.4.0; Data Source =C:\\TEST PROJECTS\\ACCESS 2003\\db1.mdb";
      oConn.Open();


      OleDbCommand oCmd = new OleDbCommand();
      oCmd.Connection = oConn;
      oCmd.CommandText = "Select grou from addcust where ID=1";

      String strgrou = "";

      using (var oReader = oCmd.ExecuteReader())
      {
          while (oReader.Read())
          {
              strgrou = oReader["grou"].ToString();
          }
      }


      string str1="a";
      string str2="b";

      oCmd.Connection = oConn;
      oCmd.CommandText = "update addcust set grou= '" + strgrou.Replace(str1, str2) + "' where id=1 ";

      oCmd.ExecuteNonQuery();


      MessageBox.Show("success");
  }
  catch (Exception ex)
  {

      MessageBox.Show(ex.Message);
  }
 
Share this answer
 
v2

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