如何随身携带数据,即使我把它放在"数据保存"因为我试图在保存在数据库中的数据之后做同样的事情,"数据保存"即使它以相同的形式出现,它也不会携带数据
private void button1_Click(object sender, EventArgs e)
{
{
try
{
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "insert into RegisterItem([Name], [Url],[Description], [Price]) values('" + ItemName.Text + "','" + ItemUrl.Text + "','" + ItemDescription.Text + "','" + ItemPrice.Text + "')";
command.ExecuteNonQuery();
MessageBox.Show("Data Saved");
txtUsername = txtID1;
ItemName = txtName1;
ItemDescription = txtDescription1;
ItemPrice = txtPrice1;
ItemName.Text = "";
ItemDescription.Text = "";
ItemPrice.Text = "";
connect.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
connect.Close();
}
string str = ItemUrl.Text;
pictureBox1.ImageLocation = str;
//string str = textBox1.Text;
// Image img = Image.FromFile(str);
// pictureBox1.Image = img;
}
}
答案 0 :(得分:0)
您想要的是将TextBox Text属性复制到另一个textBox文本属性,然后清除源文本框值。
txtID1.Text = txtUsername.Text;
txtName1.Text = ItemName.Text;
txtDescription1.Text = ItemDescription.Text;
txtPrice1.Text = ItemPrice.Text;
ItemName.Text = "";
ItemDescription.Text = "";
ItemPrice.Text = "";
此代码可以粘贴到command.ExecuteNonQuery()
下的任意位置。