0

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

2
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by codeorder
0
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
0

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
0

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

Edited by codeorder: n/a

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.