sql query to work with asp.net c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ishan Halarnkar
    New Member
    • Nov 2010
    • 2

    sql query to work with asp.net c#

    I have a database which has a table known as 'casetype' there are two fields namely 'sr' and 'skey', sr contains numeric value whereas 'skey' contains text value.

    I have a DropdownList in asp.net and i have bound the 'skey' to it so it shows all the values that are there in 'skey' once dropped down. the query for it is
    Code:
    SELECT testcase.casetype.skey FROM testcase.casetype
    what i want is,once user selects a value from dropdownlist corresponding value in 'sr' should be behind it.

    e.g when user selects 'a' the corresponding value in the database table say '8' should be present behind.\

    In short user should see a text value but a programmer will work on numeric digits.

    How can i do it? i want the sql query that connects the table casetype 'skey' 'sr' i want to print numeric digit once a user select a input.
    Last edited by NeoPa; Nov 15 '10, 01:26 PM. Reason: Added CODE tags
  • abhinavpratap
    New Member
    • Sep 2010
    • 9

    #2
    You should modify your sql query to
    SELECT testcase.casetp e.sr,testcase.c asetype.skey FROM testcase.casety pe

    Now on your aspx.cs page where you want to bind your dropdownlist as :

    Code:
    DropDownList1.Datasource = ds.Tables[0];
    DropDownList1.DataTextField = "Field Name of the table to display text"; //e.g: DropDownList1.DataTextField = "skey";
    DropDownList1.DataValueField = "Field Name of the table to set the value";  //e.g: DropDownList1.DataValueField = "sr";
    DropDownList1.DataBind();
    Happy Coding

    Comment

    • Ishan Halarnkar
      New Member
      • Nov 2010
      • 2

      #3
      Thank you. That solved my problem.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32663

        #4
        I can't help with the ASP part, but as your question specifically asks for the SQL, you would need :
        Code:
        SELECT testcase.casetype.skey
             , testcase.casetype.sr
        FROM   testcase.casetype
        How you design your control is another matter (which you will need to determine).

        Comment

        • Jose Peguero

          #5
          Answer

          first you must fill a dataset with your wanted data:
          Code:
          (SELECT testcase.casetype.skey 
               , testcase.casetype.sr 
          FROM   testcase.casetype 
          )
          then bind your dropdownlist with the dataset
          Code:
          Dropdownlist1.datasource = MyDataset;
          Dropdownlist1.DataTextField = "skey";
          Dropdownlist1.DataValueField = "sr";
          Dropdownlist1.DataBind();
          then you can get the value of the selected value this way:

          Code:
          string Value = Dropdownlist1.SelectedValue
          Last edited by Frinavale; Nov 16 '10, 03:33 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

          Comment

          Working...