Home > DeveloperSection > Forums > Bind column value to a TextBox
Simons Hood
Simons Hood

Total Post:70

Points:494
Posted on    November-14-2013 1:05 AM

 C# C# 
Ratings:


 1 Reply(s)
 705  View(s)
Rate this:

I would like to bind the value returned from a SQL Query to a Text Box:

 protected void cmbPujaName_SelectedIndexChanged(object sender, EventArgs e)

    {

        string pujaselectedid = null;

        pujaselectedid = cmbPujaName.DataValueField;

        SqlConnection con2 = null;

        con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["SRKBSDB"].ConnectionString);

        SqlDataAdapter pamt = new SqlDataAdapter("select Amount from PoojaDietyMaster where PoojaDietyMasterID =" + cmbPujaName.DataValueField, con2);

        DataSet pamtds = new DataSet();

        pamt.Fill(pamtds);

        //cmbPujaName.DataSource = pamtds;

        txtAmount.Text = pamtds -- Not sure what to add here

        txtAmount.DataBind();

    }

Please help



Pravesh Singh

Total Post:411

Points:2881
Posted on    November-14-2013 1:15 AM

Hi samuel,

You can try this:

SqlCommand c = new SqlCommand("select Amount from PoojaDietyMaster where PoojaDietyMasterID =" + cmbPujaName.DataValueField,con2);

 double c1 = (double)c.ExecuteScalar();

 txtAmount.Text = c1.ToString();

Since you are just getting one value. Theres no need to load it to a Datatable

Don't want to miss updates? Please click the below button!

Follow MindStick