Click here to Skip to main content
15,894,540 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I can't get the exact update parameterized query for ms-access database.

What I have tried:

String connectionstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + txtboxfilename.Text + "';Persist Security Info=False;";

           string SqlString = "Update DTR_Table Set Date = ?, Time = ?, Type = ?,
           Remarks = ? where Employee = @Employee";
           using (OleDbConnection conn = new OleDbConnection(connectionstring))
           {

               using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
               {
                   conn.Open();
                   cmd.CommandType = CommandType.Text;
                   cmd.Parameters.AddWithValue("@Employee", txtboxId.Text);
                   cmd.Parameters.AddWithValue("Date", DatePicker1.Text);
                   cmd.Parameters.AddWithValue("Time", TimePicker1.Text);
                   cmd.Parameters.AddWithValue("Type", combotype.Text);
                   cmd.Parameters.AddWithValue("Remarks", txtboxremarks.Text);

                   cmd.ExecuteNonQuery();
                   conn.Close();
               }

           }
Posted
Updated 30-Aug-17 22:29pm
Comments
PIEBALDconsult 30-Aug-17 23:13pm    
With OleDb, you really don't have named parameters; they're positional instead.
Member 13264296 30-Aug-17 23:32pm    
How sad. Can you give me an alternate solution for updating ms-access database? Codes or link for me as to refer?

1 solution

Last I checked, Access doesn't support named parameters. You have to specify them in the order they appear in the query.
 
Share this answer
 
Comments
Member 13264296 30-Aug-17 23:34pm    
How to specify? can you give me the picture? of how it will goes like. hehe
Richard Deeming 1-Sep-17 13:28pm    
Look at the order in which the parameters appear in your query: Date, Time, Type, Remarks, Employee.

Now look at the order in which you add the parameters to the command's Parameters collection: Employee, Date, Time, Type, Remarks.

Do you really need us to join the dots for you? :)
Dave Kreskowiak 1-Sep-17 13:42pm    
A virtual 5 for you sir.

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