Link to home
Start Free TrialLog in
Avatar of tjgrindsted
tjgrindsted

asked on

how can i make 2 sql statsment for a database

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 !?
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tjgrindsted
tjgrindsted

ASKER

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.
half solution