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

Recommended Answers

All 8 Replies

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

Then try to change SavingSalaryDetails to viruses_analysis.

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.

your problem is much more related to sql, mov your thread to ms sql pr my sql

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.

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.

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.