2016-09-14 5 views
0

どのようにデータを運ぶかは、データを保存した後でもデータを保存しようとしているため、 」出てくると、その同じ形データベースに情報を保存した後にデータを運ぶ

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;    
    } 
} 
+1

「キャリーデータ」とはどういう意味ですか? – Kinetic

+0

はtextbox = textboxと同じですが、ボタンの下またはボタンの上に置いても私には許されません。command.ExecuteNonQuery();私は他の方法を見つけることができませんでした –

+0

私は本当にあなたが言っていることを理解していません。あなたは答えを明確にする方法を見つけなければなりません。 "textbox = textboxのように"は私には意味がありません。 – Kinetic

答えて

0

に何をしたい場合は、それもデータを運ぶdoesntの保存は、ソーステキストボックスの値をクリアし、その後、別てtextBoxテキストプロパティにテキストボックスのTextプロパティをコピーすることです。

txtID1.Text = txtUsername.Text; 
txtName1.Text = ItemName.Text; 
txtDescription1.Text = ItemDescription.Text; 
txtPrice1.Text = ItemPrice.Text; 

ItemName.Text = ""; 
ItemDescription.Text = ""; 
ItemPrice.Text = ""; 

このコードは、command.ExecuteNonQuery()のどこにでも貼り付けることができます。

+0

はい、私は最初にデータベースに追加されたコンテンツを持っているので、TextBox Textプロパティを別のtextBoxテキストプロパティにコピーしてからソーステキストボックスの値をクリアしますが、 –

+0

これは質問ですか? – Kinetic

関連する問題