Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
I have to change the data in one of the fields in my table in access.
I use the update query.
but the query only deleting the old data from the table and not entering the new data with the foll code.
code:

C#
String esql = string.Format("update company_list SET company_name ='{0}' where company_name ='{1}'", edited_name, selected_name);
OleDbCommand myupdate = new OleDbCommand(esql, con);
myupdate = new OleDbCommand(esql, con);
myupdate.ExecuteNonQuery();



so, I try to change the code, but here, it says that @new_name must have a default value.
but how to set a default value

code:
SQL
using (OleDbCommand myupdate = con.CreateCommand())
             {
 myupdate.CommandText = "update company_list set company_name = @new_name where company_name = @old_name";
                 
                 myupdate.Parameters.AddWithValue("@new_name",edited_name);
                 myupdate.Parameters.AddWithValue("@old_name", selected_name);
                 
                 myupdate.ExecuteNonQuery();
}


Please help asap.
Posted
Updated 28-Mar-12 21:07pm
v2

Check the value of edited_name - it is probably blank or null, which is why it is complaining. And why the original, dangerous code deleted without replacing.
 
Share this answer
 
Comments
Monjurul Habib 30-Mar-12 4:49am    
5!
edited_name is null or empty. Make sure that you really get the new name into that variable.
 
Share this answer
 

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