質問

i am working on an sale invoice in sale invoice i am auto filling the data about product in its relevant fields, like when user enters product code in product code text box the product name and product price text boxes automatically fills themselves by retrieving data from DB, i want that when user starts type code here the program give the suggestions about all the products in the database. like when user enter 1 the program give suggestion about product codes, product codes starting with 1 show themselves and the user just selects the one he wants to.

the code I've done on text change event of product code text box is

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

how can i show suggestion about product codes in text box?

EDIT:

Its no a windform app means it's a desktop based app and i am creating it in C#.net using VS2010

役に立ちましたか?
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top