我想将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();
}
请帮忙
答案 0 :(得分:3)
添加此
txtAmount.Text=pamtds.Tables[0].Rows[0]["Amount"].ToString();
答案 1 :(得分:0)
您可以将TextBox
设置为DataSource
中的一个特定单元格值,如下所示:
txtAmount.Text=pamtds.Tables[0].Rows[0][0].ToString();
答案 2 :(得分:0)
SqlCommand c = new SqlCommand("select Amount from PoojaDietyMaster where PoojaDietyMasterID =" + cmbPujaName.DataValueField,con2);
double c1 = (double)c.ExecuteScalar();
txtAmount.Text = c1.ToString();
因为你只是得到一个值。没有必要将它加载到Datatable
答案 3 :(得分: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();