Connecting Tech Pros Worldwide Forums | Help | Site Map

conditions on executing a query

Newbie
 
Join Date: Apr 2007
Posts: 1
#1: Apr 26 '07
hello every one
i'm developing a web site using asp.net , with VB as the programming language. i want to ask: how can I implement "if else" conditions on the execution of a sql query? For example,write in the handler of a button :" IF radiobutton1 is selected THEN EXECUTE sqldatasource1 (or procedure1 ) ELSE EXECUTE sqldatasource2 ( or procedure2)". So I want execution of sql query to be appended with "IF ELSE" conditions.

thank you
Newbie
 
Join Date: Apr 2007
Location: Mexico City
Posts: 30
#2: Apr 26 '07

re: conditions on executing a query


Hi dude,

So in the VB code for the handler of a button you can do something like:
Expand|Select|Wrap|Line Numbers
  1. Dim cmd As New SqlClient.SqlCommand
  2. cmd.CommandType = CommandType.StoredProcedure
  3.  
  4. IF checkbox1.Checked= true THEN
  5.  
  6.   cmd.CommandText = "sp_someProc1"
  7.   cmd.Parameters.Add(New SqlClient.SqlParameter("paramKey1", "val1"))
  8.  
  9. ELSE
  10.  
  11.   cmd.CommandText = "sp_someProc2"
  12.   cmd.Parameters.Add(New SqlClient.SqlParameter("paramKey1", "val1"))
  13.  
  14. END IF
  15.  
  16. cmd.ExecuteNonQuery()
  17.  
  18.  
Does this help?
Reply