我正在制作销售发票,我正在自动填写有关领域的产品数据,比如当用户在产品代码文本框中输入产品代码时,产品名称和产品价格文本框通过从DB检索数据自动填写,我希望当用户在这里开始输入代码时,程序给出有关数据库中所有产品的建议。就像当用户输入1时,程序给出关于产品代码的建议,以1开头的产品代码显示自己,用户只选择他想要的代码。
我对“产品代码”文本框的文本更改事件所做的代码是
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (txtProductCode1.Text == "")
{
txtProductName1.Text = "";
txtQty.Text = "";
txtSalePrice.Text = "";
txtTotal.Text = "";
}
string sql = "select productprice, ProductName";
sql += " from dbo.productlog";
sql += " where productCode = '" + txtProductCode1.Text + "'"; // Placing ProductCode in single quotes because it's not an int column, but a varchar column, in SQL server
SqlConnection cn = new SqlConnection();
SqlCommand rs = new SqlCommand();
SqlDataReader sdr = null;
clsConnection clsCon = new clsConnection();
clsCon.fnc_ConnectToDB(ref cn);
rs.Connection = cn;
rs.CommandText = sql;
sdr = rs.ExecuteReader();
if (sdr.Read())
{
txtProductName1.Text = sdr["ProductName"].ToString();
txtSalePrice.Text = sdr["ProductPrice"].ToString();
}
else if (txtProductName.Text == "")
{
goto exitPoint;
}
else if (!sdr.Read())
{
MessageBox.Show("Data not found", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
txtProductName.Focus();
}
exitPoint:
sdr.Close();
rs = null;
cn.Close();
}如何在文本框中显示有关产品代码的建议?
编辑:
它不是一个风车应用程序,意味着它是一个基于桌面的应用程序,我正在用C#.net使用VS2010创建它
发布于 2014-02-07 11:52:49
看看这个,希望这对你有用。
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.autocompletemode%28v=vs.110%29.aspx
https://stackoverflow.com/questions/21626797
复制相似问题