Hello there,
I face this error message when I try to save a new record in Table: viruses_analysis, I would like to use the same way in the code below, but where is the error?

please be informed that I used the same way in other applications and worked very fine.
I'm confused.

Thanks in advance.

        Dim SSQl As String = "select * from viruses_analysis"
        Dim SAdapter As New OleDbDataAdapter(SSQl, Con)
        Dim SDataSet As New DataSet
        Dim RowsCount As Integer
        Dim dsNewRow As DataRow

        If Con.State = ConnectionState.Closed Then
            Con.Open()
            SAdapter.Fill(SDataSet, "SavingSalaryDetails")
            RowsCount = SDataSet.Tables("SavingSalaryDetails").Rows.Count
            dsNewRow = SDataSet.Tables("SavingSalaryDetails").NewRow()

            dsNewRow.Item("VirDate") = dtDate.Value.Date
            dsNewRow.Item("VirDay") = dtDate.Value.Day
            dsNewRow.Item("VirMonth") = dtDate.Value.Month
            dsNewRow.Item("VirYear") = dtDate.Value.Year
            dsNewRow.Item("PatID") = PatID
            dsNewRow.Item("PatName") = PatName
            dsNewRow.Item("HIV") = cmbHIV.Text
            dsNewRow.Item("HBSAG") = cmbHBSAG.Text
            dsNewRow.Item("HCV") = cmbHCV.Text
            dsNewRow.Item("VDRL") = cmbVDRL.Text
            dsNewRow.Item("COST") = Val(txtCost.Text)
            dsNewRow.Item("PAID") = Val(txtPaidValue.Text)
            dsNewRow.Item("user") = "Admin"

            ' Apply the new row
            Dim cb As New OleDb.OleDbCommandBuilder(SAdapter)
            SDataSet.Tables("SavingSalaryDetails").Rows.Add(dsNewRow)
            SAdapter.Update(SDataSet, "SavingSalaryDetails")
            Con.Close()
            SDataSet.Reset()
            ClearControls()

        Else
            SAdapter.Fill(SDataSet, "SavingSalaryDetails")
            RowsCount = SDataSet.Tables("SavingSalaryDetails").Rows.Count
            dsNewRow = SDataSet.Tables("SavingSalaryDetails").NewRow()

            dsNewRow.Item("VirDate") = dtDate.Value.Date
            dsNewRow.Item("VirDay") = dtDate.Value.Day
            dsNewRow.Item("VirMonth") = dtDate.Value.Month
            dsNewRow.Item("VirYear") = dtDate.Value.Year
            dsNewRow.Item("PatID") = PatID
            dsNewRow.Item("PatName") = PatName
            dsNewRow.Item("HIV") = cmbHIV.Text
            dsNewRow.Item("HBSAG") = cmbHBSAG.Text
            dsNewRow.Item("HCV") = cmbHCV.Text
            dsNewRow.Item("VDRL") = cmbVDRL.Text
            dsNewRow.Item("COST") = Val(txtCost.Text)
            dsNewRow.Item("PAID") = Val(txtPaidValue.Text)
            dsNewRow.Item("user") = "Admin"

            ' Apply the new row
            Dim cb As New OleDb.OleDbCommandBuilder(SAdapter)
            SDataSet.Tables("SavingSalaryDetails").Rows.Add(dsNewRow)
            SAdapter.Update(SDataSet, "SavingSalaryDetails")
            Con.Close()
            SDataSet.Reset()
            ClearControls()
        End If

Please don't care about "SavingSalaryDetails", I copied it from other "working" code.

Dear Jx,
That's not helping.

in the SQL statement I mentioned the table I want to add data to.

thanks any way.

hai ASWEDAN,

i have a small doubt

let me know what does the statement means at line no 7 ?

If Con.State = ConnectionState.Closed Then

in the above statement r u going to assigning values are comparing values

i donot have a great knowledge in vb.net but it seems to be invalid condition check

i think it will be like as follows

If Con.State == ConnectionState.Closed Then

check it once let me know the status.

Edited 3 Years Ago by radhakrishna.p: giving clarity on the solution

Dear radhakrishna.p,
The line you mentioned is to check if the connection is opened or closed, and it has nothing related to the problem. I tried your suggestion, but it gave me error message: "Expression expected" and not worked.

The problem is in the "save" stage, exactly in applying the changes to the datarow.

still looking for a solution.
Thanks mate.

Edited 3 Years Ago by ASWEDAN: error in "or"

Dear Lethugs,
My problem is common in dealing with "MS Access Databases" as well.

I found the solution!!

just make sure that The table columns names in the database are not keywords used by Visual Basic, and the data types are correct.

Thanks all for helping me, it is working now.

This question has already been answered. Start a new discussion instead.