Results 1 to 9 of 9

Thread: [RESOLVED] Running different SQL queries based on user selection

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2010
    Location
    UK
    Posts
    288

    Resolved [RESOLVED] Running different SQL queries based on user selection

    I want to run a different SQL statement depending what the user types into a text box. So if the user selects "Sales" it runs the Sales Query, if the user selects "Accounts" it runs the accounts query etc etc.
    I have tried a IF statement as shown below but i get an error message " The path is not a legal form"

    HTML Code:
    Dim ConnectionString As String = WebConfigurationManager.ConnectionStrings("con").ConnectionString
    
            Dim soundPath As String
            Dim selectSQL As String
    
            If txtDept.Text = "Accounts" Then
                selectSQL = "SELECT * FROM vAccounts"
    
            End If
    
            If txtDept.Text = "Sales" Then
                selectSQL = "SELECT * FROM vSales"
            End If
    
            If txtDept.Text = "Logistics" Then
                selectSQL = "SELECT * FROM vLogistics"
            End If
    
    
    
            Dim myconnection As New SqlConnection(ConnectionString)
            Dim cmd As New SqlCommand(selectSQL, myconnection)
            Dim reader As SqlDataReader
    
    
            Try
    
                myconnection.Open()
                reader = cmd.ExecuteReader()
                reader.Read()
    
                'Fill the controls
    
                txtDept.Text = reader("Dept").ToString()
                txtStaffID.Text = reader("StaffID").ToString()
    
    
                reader.Close()
    
    
            Catch ex As Exception
             lblError.Text = Err.Description
            Finally
                myconnection.Close()
    
            End Try
    
    Last edited by ConfusedAgain; Jan 11th, 2011 at 03:02 AM. Reason: Changed the SQL as it was showing a misleadin query

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width