我正在尝试创建一个可供用户购买商品的市场计划。我已经编写了以下代码,但它给了我一个我无法解决的问题。如果有人可以帮助我,我将非常感激。
该代码具有以下功能:(请参见pic) 用户购买产品,该信息将保存在数据库表中。
但是有一个问题:(请参阅database pic) 有关购买的信息不会保存在用户字段中,但会创建另一个字段。
有人可以帮我吗?
private void User_Load(object sender, EventArgs e)
{
conect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = conect;
command.CommandText = "select * from Item ";
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
combo.Items.Add(reader["Item_Name"].ToString());
}
conect.Close();
}
private void combo_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbCommand command = new OleDbCommand();
command.Connection = conect;
command.CommandText = "select * from Item where Item_Name='"+combo.Text+"'";
conect.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
item_id.Text = reader["Item_ID"].ToString();
Price.Text = reader["Item_Price"].ToString();
}
conect.Close();
}
private void Buy_Click(object sender, EventArgs e)
{
conect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = conect;
command.CommandText = "insert into Sign_Up ([Item_Name],[Price]) values ('" + combo.Text + "','" + Price.Text + "')";
if (combo.Text == "")
{
MessageBox.Show("Please Chose An Item");
}
else
{
MessageBox.Show("Success");
command.ExecuteNonQuery();
conect.Close();
}
}