I want to stick this

Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM 0 WHERE Id = 1", con)
                    Dim reader As OleDbDataReader = cmd.ExecuteReader()
                    If Not reader.HasRows Then
                        MsgBox("Data does not exist")
                    Else
                        MsgBox("Data Exists")
                    End If

and this

If Inc <> -1 Then

                    Dim cb As New OleDb.OleDbCommandBuilder(da)
                    Dim dsNewRow As DataRow
                    da.Fill(ds, "0")dsNewRow = ds.Tables("0").NewRow()


                    dsNewRow.Item("Field1") = TextBox2.Text

                    ds.Tables("0").Rows.Add(dsNewRow)

                    da.Update(ds, "0")

                    MsgBox("New Record added to the Database")

                    con.Close()
                    MsgBox("Database is now Closed")

Into a If Then Statement that doesnt allow the second code to execute if the Data Exists
And to allow code to execute if data doesnt exist

Recommended Answers

All 6 Replies

If Not reader.HasRows Then
                        MsgBox("Data does not exist")
                    Else
                        MsgBox("Data Exists")
                        Exit Sub '// skip all remaining code in the Sub.
                    End If

ok works thanks codeorder !!

Apparently it has rows because evertime i type in a new record the if not reader has rows statement is ignored any ideas

Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM 0 WHERE Id = 1", con)
                    Dim reader As OleDbDataReader = cmd.ExecuteReader()
                    If Not reader.HasRows Then
                        MsgBox("Data does not exist")
                    Else
                        MsgBox("Data Exists")
                        Exit Sub
                    End If

I'm a bit confused on your new question.
What's not responding as needed? Does not Exit Sub?

No it exits the sub, but when i type in data that does not exist it says it exist

Then your rows are empty when first running the code.

Be a part of the DaniWeb community

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