Click here to Skip to main content
15,900,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hey Guys,

I write code for update database but it can't be update the database how to solve this problem tell me please...!!!
I use the Microsoft Access database.
My code is
C#
cmd = new OleDbCommand("Update [hoddo] set [hoddo]=[@lk] where [ID]=[@id]", con);
      cmd.Parameters.AddWithValue("@id", dgrow);
      cmd.Parameters.AddWithValue("@lk", textBox1.Text);
      cmd.ExecuteNonQuery();
Posted
Updated 2-Mar-13 8:04am
v4
Comments
Maciej Los 2-Mar-13 14:24pm    
Where do you place your database?
What is dgrow?

Access doesn't use named parameters. Your parameters could be specified with "@?" instead of names like "@lk". When you create your parameter objects, they must be specified in the order they appear in the SQL statement. Currently, your parameters are specified in the wrong order.
 
Share this answer
 
Comments
Maciej Los 2-Mar-13 14:52pm    
In MS Access query we can define parameters ;)
See my solution.
Dave Kreskowiak 2-Mar-13 15:20pm    
I said you couldn't define NAMED parameters. I didn't say you couldn't define parameters at all.

I see they changed things in 2007 and above. Now you can use name parameters, but that's a funky implementation they've got.

I don't use Access for anything because of it's limitations and screwed up implementation. It's a DESKTOP database, not something I would use in a multiuser system.
Maciej Los 2-Mar-13 15:29pm    
I'm almost sure that you said we couldn't define named parameters, because you wrote: Your parameters could be specified with "@?" instead of names like "@lk".. ;)
If i'm not wrong, this functionality is accesible starting from Access'97 ;)
You need to define parameters, like this:
SQL
PARAMETERS [pID] INT, [pHoddo] INT;
SELECT ...
FROM ...
WHERE [hoddo]=[pHoddo] AND [ID]=[pID]


More at: http://msdn.microsoft.com/en-us/library/office/bb208916%28v=office.12%29.aspx[^]
 
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