Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    1

    Unanswered: retrieve data from db with combobox selected value

    Hi friends...

    My q is, In a vb .net form i have 1combobox(EMpid),textbox1(empName), textbox2(EMpdetail) with SQL Server Db as empdetails (it contain EMpid,empName,EMpdetail) from the table i have to bind the data in combobox
    with the help of code below..

    dim con as new sqlconnection(...............)
    dim da as new sqldataadapter
    dim ds as new dataset
    dim cmd as new sqlcommand
    dim dt as new datatable

    con.open()
    da= new sqldataadapter("select *from empdetails ",con)
    da.fill(ds,"empdetails")
    combobox1.datasource=ds.tables("empdetails")
    combobox1.displaymember="EMpid"

    thro the above code i will bind the empid in combobox

    my q is..

    If i select one particular empid value in combobox then it should display the respective empName in txtbox1 ,EMpdetail in txtbox2 if it doesnt available any data in db then i will enter new data respective txtboxes and that should be added in db with the help of button event.

    pls gve me a code

    pls reply ASAP

  2. #2
    Join Date
    Dec 2008
    Posts
    135
    u can write a sp for this
    create dbo.usp_samplesp
    (
    @empid int
    )
    )
    AS
    SET NOCOUNT ON
    BEGIN

    select * from empdetails where empid = @empid
    END
    SET NOCOUNT OFF
    and pass the empid required then it will return the datatable
    and from front end u can assign that values in to ur textboxs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •