Hello i got trouble to add data
i got error saying:
OleDbException was unhandled

here's the code:

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        Dim com As New OleDbCommand
        com.Connection = con
        com.CommandText = "insert into Watches values(" & txtWatchId.Text & ",'" & txtWatchBrand.Text & "','" & _
                            txtWatchModel.Text & "','" & txtManufacturer.Text & "'," & txtCountryOfOrigin.Text & "','" & _
                            cmbType.Text & "','" & txtDescription.Text & "'," & txtPrice.Text & "'," & txtPriceInclVat.Text & ")"

        com.ExecuteNonQuery()
        MsgBox("Record Inserted")
        Call fill_combo()
        Call populate()
        Call clear()
    End Sub

any help please

I think your SQL string is not well formatted. This is correct, I think.

com.CommandText = "insert into Watches values(" & txtWatchId.Text & ",'" & txtWatchBrand.Text & "','" & _
txtWatchModel.Text & "','" & txtManufacturer.Text & "','" & txtCountryOfOrigin.Text & "','" & _
cmbType.Text & "','" & txtDescription.Text & "','" & txtPrice.Text & "'," & txtPriceInclVat.Text & ")"

Moreover, also use try-catch exception handling to know the exact source and exact error message.

here's the code:

Try
            Dim com As New OleDbCommand
            com.Connection = con
            com.CommandText = "insert into Details values(" & txtBoxNo.Text & ",'" & txtBoxName.Text & "','" & _
                                txtBoxGender.Text & "','" & txtBoxDepartment.Text & "'," & txtBoxTotalMark.Text & ")"

            com.ExecuteNonQuery()
            MsgBox("Record Inserted")
            Call Md_FillCombo()
            Call Md_Settings()
            Call Md_ClearAll()
        Catch exp As Exception
            MsgBox(exp.ToString())
        End Try

when trying to add i got this error:
No value given for one or more required parameter at Sys..

>when trying to add i got this error: No value given for one or more required parameter at Sys..

Can you show us your table structure of Details table?

here's the code:

Try
            Dim com As New OleDbCommand
            com.Connection = con
            com.CommandText = "insert into Details values(" & txtBoxNo.Text & ",'" & txtBoxName.Text & "','" & _
                                txtBoxGender.Text & "','" & txtBoxDepartment.Text & "'," & txtBoxTotalMark.Text & ")"

            com.ExecuteNonQuery()
            MsgBox("Record Inserted")
            Call Md_FillCombo()
            Call Md_Settings()
            Call Md_ClearAll()
        Catch exp As Exception
            MsgBox(exp.ToString())
        End Try

when trying to add i got this error:
No value given for one or more required parameter at Sys..

helps please Urgent i need to submit this on Frinday
please help

Your code:

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        Dim com As New OleDbCommand
        com.Connection = con
        com.CommandText = "insert into Watches values(" & txtWatchId.Text & ",'" & txtWatchBrand.Text & "','" & _
                            txtWatchModel.Text & "','" & txtManufacturer.Text & "'," & txtCountryOfOrigin.Text & "','" & _
                            cmbType.Text & "','" & txtDescription.Text & "'," & txtPrice.Text & "'," & txtPriceInclVat.Text & ")"

        com.ExecuteNonQuery() <-- Break your debugger here
        MsgBox("Record Inserted")
        Call fill_combo()
        Call populate()
        Call clear()
    End Sub

Put a breakpoint where I marked in the code above and when you hit that breakpoint get the value of com.CommandText and post that here. Also post the FULL error message from the exception.

I guess the INSERT syntax would look like this:

"INSERT INTO Table_Name(Field1, Field2, Field3) VALUES ('" & Text1.Text &"','"& Text2.Text &"','" & Text3.Text &"')"

I guess the INSERT syntax would look like this:

"INSERT INTO Table_Name(Field1, Field2, Field3) VALUES ('" & Text1.Text &"','"& Text2.Text &"','" & Text3.Text &"')"

No it should look like

INSERT INTO Table_Name(Field1, Field2, Field3) Values ('Val1', 'Val2', 'Val3')

The original post did not have the insert columns defined which could cause a problem if one of the columns is an identity column. It could also be a problem if one of the values that wasn't wrapped with a '' had a @ParameterName value, which sort of matches the partial exception he pasted

Here's the com.commandtext
"insert into Watches values(W005,'Rolex','Air-King','Rolex SA',Switzerland','Automatic','The Air-King could be considered the "entry level" model from Rolex. It is 34mm in diameter and comes with an Oyster bracelet by default. The Air-King does not have a Date.',4200',4830)"

hope a reply

That still does not help because you have not posted the structure for the table Watches . I don't know if your column names/values are aligned properly and if you have the right data type.

What structure, for example WatchID, WatchBrand??
Give me an example??

If u cant undersatand at all, can i email the program to U??

You can .zip the program and attach it to this thread. Hit the "Go Advanced" button next to "Post Quick Reply" and it will let you manage attachments.

Here's the program

Your insert query has problem:

Here is correction. However, use the parameters suggested by Mr. sknake.

com.CommandText = "insert into Watches values('" & txtWatchId.Text & "','" & txtWatchBrand.Text & "','" & _
                            txtWatchModel.Text & "','" & txtManufacturer.Text & "','" & txtCountryOfOrigin.Text & "','" & _
                            cmbType.Text & "','" & txtDescription.Text & "'," & txtPrice.Text & "," & txtPriceInclVat.Text & ")"

Yes thanks adatapost everything's working

Thanks.

Mark this thread as Solved if you get solution.

Be a part of the DaniWeb community

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