locked
Merge Column into one. RRS feed

  • Question

  • User-977579175 posted

    I have two colums in database table. I need to both columns in DropDownlist to show to the user but passed value should be one column.

    Below is my code:

    qry="Select BankCode, BacnkName from MyBanks where UID='"+uid+"'";

    adapt=new SqlAdapter(qry,mycoon);

    adapt.fill(ds,"MyBanks");

    cmbBank.DataSource=ds["MyBanks"];

    cmbBank.DataTextField="BankName";//I need both code and name

    cmbBank.DataValueField="BnkCode";

    cmbBank.DataBind();

    Friday, May 25, 2012 3:45 AM

Answers

  • User-183374066 posted

    qry="Select BankCode, BacnkName from MyBanks where UID='"+uid+"'";

    change it to

    qry="Select BankCode + ' ' + BacnkName as BankDetail from MyBanks where UID='"+uid+"'";

    and if your bankcode or bacnkName (is it bacnkName or bankName) isn't char/varchar/nvarchar either use

    CAST(ItemId as VARCHAR(50)) as col1

    Or

     CONVERT(VARCHAR(50),ItemId) as colI1

    suppose your bank code is int than you have to convert it to varchar

    qry="Select CAST(BankCode as varchar(100)) + ' ' + BacnkName as BankDetail from MyBanks where UID='"+uid+"'";




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 26, 2012 6:34 PM
  • User-1635004338 posted

    Hi,

    Anyone who has the same problem, please refer this thread: http://forums.asp.net/t/1807386.aspx

    Thanks,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 29, 2012 4:26 AM

All replies