Results 1 to 3 of 3

Thread: Procedure for run two select command

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2006
    Posts
    43

    Procedure for run two select command

    Hi all!

    I have table Product includes field : ID,Product,Price and table Customer include field: JID,Name. I want write a procedure SQL for search. In my page Search.aspx (by C#) include a textbox (ID=name) and a DropDownlist ( include two values: Customer and Product) and a Submit button. I want when user type a name into textbox and selected a value in DropDownlist and click submit. If value of DropDownlist = Product then my procedure will run SQL command " Selec * from Product......" . If value of DropDownlist = Customer then my procedure will run SQL " Select * from Customer.....". The result will a GridView. Please help me

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Procedure for run two select command

    C# Code:
    1. SqlCommand command = new SqlCommand("SELECT * FROM " + myDDL.Text, connection);
    Just note that I don't know if a DropDownList has a Text property because I've never used one, but you can substitute whatever returns the displayed value if necessary.

    Now, that may change if you want to include the value in the TextBox but you haven't indicated where it comes in.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: Procedure for run two select command

    jmc is spot on. The .Text property of the DropDownList returns the SelectedValue of the control. Good luck with you project.

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