2017-05-09 21 views
0

テキストボックスとボタンを使用してデータベース内のデータを更新したり削除したりする方法については問題があります。データベースの削除と更新C#

マイ挿入コードは次のとおりです。

private void button4_Click(object sender, EventArgs e) 
    { 
     try 
     { 



      string query = "insert into Prodaja values (@Prodajalec,@Prodajalna,@Kupec,@Vozilo,@DatumNakupa)"; 

      using (connection = new SqlConnection(connectionString)) 
      using (SqlCommand command = new SqlCommand(query, connection)) 
      { 

       connection.Open(); 
       command.Parameters.AddWithValue("@Prodajalec", textBoxProdajalec.Text); 
       command.Parameters.AddWithValue("@Prodajalna", textBoxProdajalna.Text); 
       command.Parameters.AddWithValue("@Kupec", textBoxKupec.Text); 
       command.Parameters.AddWithValue("@Vozilo", textBoxVozilo.Text); 
       command.Parameters.AddWithValue("@DatumNakupa", textBoxDatumNakupa.Text); 
       command.ExecuteNonQuery(); 



      } 

      MessageBox.Show("Uspešno dodano");    
      this.prodajaTableAdapter.Fill(this.prodajaDataSet.Prodaja); 

     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
    } 

私は別の方法をいくつか試してみましたが、彼らは本当にうまくdidntの。どんな助けもありがとう!

+1

を削除しますか? –

答えて

1

あなたはinsert対updateステートメントの構文を混同しているようです。

Insert statement: 
insert into #table (col1,col2) values ('col1','col2') 

Update statement 
Update #table set col1 = 'col1', col2 = 'col2' where id = 'id' 

EDIT:あなたはどのような出力/エラーメッセージが表示されます。構文

Delete from #table where id = 'id' 
+0

いや、私は間違ったコードをコピーしたことを修正しました。投稿されたコードiveは動作しますが、私はこのベースから更新して削除する方法を知らない。 –

+0

上記の私の構文を更新のために使うことができます。いくつかのユニークなフィールドに基づいて特定のレコードの場所を追加するだけです。その答えをdelete構文で更新します。 – ThatChris

関連する問題