here's my code

Dim sql As String = "INSERT INTO tbldailysales(date, totalprice)VALUES(@date, @totalprice)"
        cmd = New OleDbCommand(sql.ToString, con)
        cmd.Parameters.AddWithValue("@date", lblday.Text)
        cmd.Parameters.AddWithValue("@totalprice", lblstotal.Text)
        cmd.ExecuteNonQuery()

Recommended Answers

The only thing I can see is that you're missing the final semi-colon (;) on the statement.
If it isn't that, can you provide the actual error message?

Jump to Post

All 4 Replies

The only thing I can see is that you're missing the final semi-colon (;) on the statement.
If it isn't that, can you provide the actual error message?

Use @name parameters with SQLDB. For OleDB you have to use ? as s placeholder. Plese see Use Parameterized Queries to Avoid SQL Injection Attacks. When using SQLDB, parameters can be added by name. With OleDB you must add them in the order in which they appear in the query.

Agreed with Reverend Jim. Use Question Mark i.e. ? as a placeholder of a Parameter.
Your SQL Statement shoud be

Dim sql As String = "INSERT INTO tbldailysales(date, totalprice) VALUES(?, ?)"

But, what was the error report. Is your connection Object Opened. I did not find it in your code.

my connection is open. but i can add now, thanks for helping guys :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.