none
Reterieve data from database to text box when combo box value changes RRS feed

  • Question

  • Hello

    I am developing an application in asp.net C#

    usin SQL SERVER 2008

    I need code for retrieve data from database to textbox when changing combox value..

    Pls consider my question and reply

    • Moved by Bob Beauchemin Sunday, November 11, 2012 4:07 PM Moved to the closest relevent forum for best results. Also suggest posting to ASP.NET forums. (From:.NET Framework inside SQL Server)
    Sunday, November 11, 2012 6:35 AM

Answers

  • Hi,

    You can do as follows:

    1)Write the below code in ComboBox Selection Changed Event

    SqlConnection conn=new SqlConnection("Your Connection string");
    
    conn.Open();
    
    SqlCommand cmd=new SqlCommand("Select column1 from tableName where columnId="+comboBox.ValueMember+"",conn);
    
    SqlDataReader dr=cmd.ExecuteReader();
    
    if(dr.Read())
    
    {
    
       textBox1.Text=dr["column1"].ToString();
    
    }



    PS.Shakeer Hussain

    • Proposed as answer by Alexander Sun Monday, November 12, 2012 2:06 AM
    • Marked as answer by Alexander Sun Thursday, November 22, 2012 7:06 AM
    Sunday, November 11, 2012 7:30 AM

All replies

  • Hi,

    You can do as follows:

    1)Write the below code in ComboBox Selection Changed Event

    SqlConnection conn=new SqlConnection("Your Connection string");
    
    conn.Open();
    
    SqlCommand cmd=new SqlCommand("Select column1 from tableName where columnId="+comboBox.ValueMember+"",conn);
    
    SqlDataReader dr=cmd.ExecuteReader();
    
    if(dr.Read())
    
    {
    
       textBox1.Text=dr["column1"].ToString();
    
    }



    PS.Shakeer Hussain

    • Proposed as answer by Alexander Sun Monday, November 12, 2012 2:06 AM
    • Marked as answer by Alexander Sun Thursday, November 22, 2012 7:06 AM
    Sunday, November 11, 2012 7:30 AM
  • Thanks dear
    Sunday, November 11, 2012 1:10 PM