0

I have a simple button which end the Work day in my Management System. Sadly when pressed all fine but the Column in my Table is still empty.

Here is the code:

Dim sql As String = "UPDATE [TA-Arbeitszeit] SET Ende = @ende WHERE Personal_nr = @Personal_nr"
    Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\recycle2000.mdb;"),
             cmd As New OleDbCommand(sql, conn)
        conn.Open()
        cmd.Parameters.Add("@Personal_nr", OleDbType.VarChar).Value = tbxUserInput.Text.Trim()
        cmd.Parameters.Add("@ende", OleDbType.VarChar).Value = DateTime.Now.ToString("G")
        Dim icount As Integer = cmd.ExecuteNonQuery

    End Using
1
  • 3
    Why are you using a text column to store dates? Access databases have a dedicated data type for dates and times. Use it. Commented Apr 28, 2020 at 9:38

1 Answer 1

1

Access doesn't fully support named parameters. Although you can and should use parameter names for your own clarity, Access ignores them. It simply inserts your parameter values into the SQL code in the order they are added. That means that they need to be added in the same order as they appear in the SQL code. Your SQL code has @ende before @Personal_nr but when you add parameters you do it the other way around. Switch the order in which you add the parameters and you should hopefully be fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Okay, i use parameters because i don't want to have any SQL-Injections. And i didn't knew about the order that my parameters should be with Access. Thank you. I can see now the time inserted into the End column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.