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




Reply With Quote