0

Good day to everyone here... Please I've been trying to write this code to update my data in a database I've created in Access through Vb.Net. I want it in a way that after I have saved a data and want to correct or make an update to it, then it will be possible...

The Data types for all the fields are Number

Just that aside MealID the other two fields, I've changed the field size of those fields in Access to Double where*MealID** is Long Integer

Please I'll be very grateful to any help I can get.. Thank you...

conn.Open()
     cmd = conn.CreateCommand()
     cmd.CommandType = CommandType.Text
     cmd.CommandText = "update tblsales 
     set MealID = '" + txtID.Text + "' 
       where Waakye ='" + txtwaakye.Text +
       "' and Salad = '" + txtsalad.Text +  "'"
cmd.ExecuteNonQuery()
cmd.Close()

8A1M1n
  • 3
  • 3
  • `MealID` is not a string Type, but you're passing it as a string. -- You need to use Parameters to build a query. It's mandatory. The fact that you're somewhat *allowed* to use string concatenation is not an excuse. -- *a database I've created in Access*: what is the `mysql` tag for? – Jimi Jul 03 '22 at 14:38
  • Please can re write my code using that for me, I don't you know how to use that... Thank you... – 8A1M1n Jul 03 '22 at 14:44
  • 2
    [OleDbParameter](https://learn.microsoft.com/en-us/dotnet/api/system.data.oledb.oledbparameter) Class. -- Note that the Connection and Command objects must be declared in-place with `Using` statements. **Do not** store the Connection. Especially with an Access db. See the linked documentation. – Jimi Jul 03 '22 at 14:48
  • Apostrophe delimiters are used only for text type field. Remove them. For using parameters, review https://stackoverflow.com/questions/542510/how-do-i-create-a-parameterized-sql-query-why-should-i – June7 Jul 03 '22 at 16:26
  • Thank you... Now I am able to run the code using the parameters but I don't see the changes or the update in the database... – 8A1M1n Jul 04 '22 at 05:42

0 Answers0