By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,363 Members | 689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,363 IT Pros & Developers. It's quick & easy.

conditions on executing a query

P: 1
hello every one
i'm developing a web site using , 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
Apr 26 '07 #1
Share this Question
Share on Google+
1 Reply

P: 30
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
  4. IF checkbox1.Checked= true THEN
  6.   cmd.CommandText = "sp_someProc1"
  7.   cmd.Parameters.Add(New SqlClient.SqlParameter("paramKey1", "val1"))
  9. ELSE
  11.   cmd.CommandText = "sp_someProc2"
  12.   cmd.Parameters.Add(New SqlClient.SqlParameter("paramKey1", "val1"))
  14. END IF
  16. cmd.ExecuteNonQuery()
Does this help?
Apr 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.