0

我想将从 SQL 查询返回的值绑定到文本框:

 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();
    }

请帮忙

4

4 回答 4

3

添加这个
txtAmount.Text=pamtds.Tables[0].Rows[0]["Amount"].ToString();

于 2013-11-14T03:44:07.250 回答
0

您可以设置TextBox为一个特定的单元格值,DataSource如下所示:

txtAmount.Text=pamtds.Tables[0].Rows[0][0].ToString();
于 2013-11-14T03:43:52.113 回答
0
 SqlCommand c = new SqlCommand("select Amount from PoojaDietyMaster where PoojaDietyMasterID =" + cmbPujaName.DataValueField,con2);
 double c1 = (double)c.ExecuteScalar(); 
 txtAmount.Text = c1.ToString();

因为你只是得到一个值。无需将其加载到数据表

于 2013-11-14T03:44:20.027 回答
0
txtAmount.Text=pamtds.Tables[0].Rows[0]["Amount"].ToString();

  make sure the field names in the select result have 'Amount' column in it..!!

删除此代码

 txtAmount.DataBind();
于 2013-11-14T04:37:21.567 回答