BIND COLUMN VALUE TO A TEXTBOX

Simons Hood

Total Post:70

Points:494
Posted by  Simons Hood
C# 
C#
 1131  View(s)
Ratings:
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

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Bind column value to a TextBox

    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

      Modified On Apr-03-2018 05:53:38 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!