我正在尝试发票项目,当我选择下拉列表项目时,我应该从数据库中获取价格和折扣并显示在文本框中,然后获取价格值到文本框但是我怎样才能得到另一个值是折扣到文本框如何绑定第二个文本框值...请一些身体帮助我....谢谢你
protected void Page_Load(object sender, EventArgs e)
{
if (! IsPostBack )
{
populatedropproduct();
}
}
private void populatedropproduct()
{
SqlCommand com = new SqlCommand("SELECT * FROM invoice1", conn);
com.Connection.Open();
SqlDataReader rdr = com.ExecuteReader();
dropproduct.DataSource = null;
dropproduct.DataTextField = "PRODUCT_NAME";
dropproduct.DataValueField ="PRICE";
dropproduct.DataBind();
dropproduct.Items.Insert(0, new ListItem("--Select Item--", "0"));
com.Connection.Close();
}
protected void txtinvoice_TextChanged(object sender, EventArgs e)
{
}
protected void txtcustomer_TextChanged(object sender, EventArgs e)
{
}
protected void dropproduct_SelectedIndexChanged(object sender, EventArgs e)
{
String title = dropproduct.SelectedItem.Value;
title = dropproduct.SelectedItem.Value;
try
{
SqlCommand com = new SqlCommand("SELECT PRICE,[DISCOUNT%] FROM invoice1 WHERE [PRODUCT NAME]=@title", conn);
SqlParameter param0 = new SqlParameter();
param0.ParameterName = "@title";
param0.SqlDbType = System.Data.SqlDbType.NVarChar;
param0.Value = title;
com.Parameters.Add(param0);
com.Connection.Open();
SqlDataReader rdr = com.ExecuteReader();
txtprice.Text = title.ToString();
com.Connection.Close();
com.Connection.Dispose();
}
catch(Exception s)
{
HttpContext.Current.Response.Write("Error Occured " + s.Message);
}
}
答案 0 :(得分:0)
param0.ParameterName = "@title";
param0.SqlDbType = System.Data.SqlDbType.Int;
param0.Value = title;
您的代码说param @title
是整数,但您尝试将其放入字符串中。
答案 1 :(得分:0)
在第
行param0.SqlDbType = System.Data.SqlDbType.Int;
您将类型或参数设置为Int
。但是你的PRODUCT NAME
肯定是一个字符串。所以将该行更改为
param0.SqlDbType = System.Data.SqlDbType.VarChar;
或
param0.SqlDbType = System.Data.SqlDbType.NVarChar;
根据PRODUCT NAME
列类型的类型。
答案 2 :(得分:0)
替换
param0.SqlDbType = System.Data.SqlDbType.Int;
使用
param0.SqlDbType = System.Data.SqlDbType.Varchar;