how can i make 2 sql statsment for a database

tjgrindsted
tjgrindsted used Ask the Experts™
on
Hi im "new" to this, so hope someone can help me, guide me.

Im using these codes, that i use to get data from a database.
(dont know if the 1. is better then the 2. or if the 2. is better then the 1.)
Using connection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("MyConnStr").ConnectionString)
            Using command As OleDbCommand = New OleDbCommand("select * from TableTest", connection)
                command.Connection.Open()
                Using reader As OleDbDataReader = command.ExecuteReader(CommandBehavior.CloseConnection)
                    While reader.Read()
                        Response.Write(reader("record") & "<br />")
                    End While
                End Using

            End Using
        End Using

Open in new window


Using connection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("MyConnStr").ConnectionString)
            Using command As OleDbCommand = New OleDbCommand("select * from TableTest", connection)
                command.Connection.Open()
                Using reader As OleDbDataReader = command.ExecuteReader(CommandBehavior.CloseConnection)
                    If reader.HasRows Then
                        Do While reader.Read()
                            Response.Write(reader("record") & "<br />")
                        Loop
                    Else
                        Response.Write("Ingen data i db")
                    End If
                    reader.Close()
                End Using

            End Using

        End Using

Open in new window


My question is

how can i add 2 sql statsment to that code !?

First of all i need to know is an record is in the db.
and if its in the db i need to know if status is activ or notactiv

"select * from TableTest where email = 'test@tester.dk'"
if this is OK, then i need to know if Status is "activ" or "notactiv"

how do i do that and how do i response.write one thing if email is not in the db, and another thing if the email is in the db and the status is activ and a 3. response.write if its in the db and the status is notactiv.

BTW do i need to add the reader.close() between the end.while and end.using, in code no. 2 !?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Engineer
Top Expert 2009
Commented:
Can you describe tabletest columns?
Is Status defined in tabletest?
What type is Status?
>> code 2 looks better without reader.close only if you would like to have the "No rows ins this database call" to your page.

>>BTW do i need to add the reader.close() between the end.while and end.using, in code no. 2 !?
No, using do that for you.

Note: If you use SQL server as database engine it is quicker to use SqlConnection, SqlCommand, etc. than OleDb classes. (similar code fiddrente classes)

Author

Commented:
Hi Mas_Oz2003

tabletest look lige this
TableTest
- id            (is the ID)
- email      (the email)
- status     (the status active or notactiv)
- name     (Users name)
- age         (Users DOB)

So i need to see if the email typed in Request.Form("MasterID$newsletter") (or just like a write test@tester.dk) if its in the db then i need to know if the status is activ or notantic, i Can make the value for activ = 1 and notactiv = 0 if its better.

And then i need to call one of 3 multiviews depending on....
1. the email is not in the DB.
2. the email is in the db and the status is activ.
3. the email is in the db and the status is notactiv.

Im using Access DB

Hope this info is ok.

Author

Commented:
half solution

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial