我有多个数据,database
所以我需要将它们添加到不同的textBoxes
. 这是我的代码
private void Search_button1_Click(object sender, EventArgs e)
{
string query = string.Empty;
if (ID_textBox1.Text.Trim().Length > 0)
{
try
{
query = "SELECT ProductName,ProductDescription,SellPrice FROM Table2 WHERE ProductID='" + ID_textBox1.Text + "'";
SqlConnection Conn = CreateConnection.create_connection();
SqlCommand cd = new SqlCommand(query, Conn);
SqlDataReader reader = cd.ExecuteReader();
while (reader.Read())
{
Name_textBox2.Text = reader["ProductName"].ToString();
Description_textBox3.Text = reader["ProductDescription"].ToString();
Unit_Price_textBox5.Text = reader["SellPrice"].ToString();
}
reader.Close();
Name_textBox2.Text = Name_textBox2.Text;
Description_textBox3.Text = Description_textBox3.Text;
QTY_textBox4.Text = 1.ToString();
Unit_Price_textBox5.Text = Unit_Price_textBox5.Text;
Price_textBox6.Text = (decimal.Parse(QTY_textBox4.Text) * decimal.Parse(Unit_Price_textBox5.Text)).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}