2010-12-13 8 views
0
OleDbConnection _connection = new OleDbConnection(); 
     StringBuilder ConnectionString = new StringBuilder(""); 
     ConnectionString.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;"); 
     ConnectionString.Append(@"Extended Properties=Paradox 5.x;"); 
     ConnectionString.Append(@"Data Source=C:\Clients\Rail\Wheelsets;"); 
     _connection.ConnectionString = ConnectionString.ToString(); 
     _connection.Open(); 
     OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Vehicles;", _connection); 
     DataSet dsRetrievedData = new DataSet(); 
     da.Fill(dsRetrievedData); 
     OleDbCommandBuilder builder = new OleDbCommandBuilder(da); 
     da.InsertCommand = builder.GetInsertCommand(); 
     ////Insert new row 
     DataRow rowNew = dsRetrievedData.Tables[0].NewRow(); 
     rowNew[dsRetrievedData.Tables[0].Columns[0].ColumnName] = "978"; 
     rowNew[dsRetrievedData.Tables[0].Columns[1].ColumnName] = "222"; 
     rowNew[dsRetrievedData.Tables[0].Columns[4].ColumnName] = "999"; 
     rowNew[dsRetrievedData.Tables[0].Columns[5].ColumnName] = "999"; 
     rowNew[dsRetrievedData.Tables[0].Columns[6].ColumnName] = "999"; 
     dsRetrievedData.Tables[0].Rows.Add(rowNew); 
     dsRetrievedData.Tables[0].AcceptChanges(); 
     dsRetrievedData.AcceptChanges(); 
     int result = da.Update(dsRetrievedData); 

thatsは私が使用するコードです。あなたが見ることができるように、私はパラドックステーブルを持っています。いくつかの結果がすべて0の終わりに0になります。 私の間違いは何ですか?OleDBAdapterを使用してテーブルに行を挿入できません

ありがとうございます。

- =ノアム= -

答えて

0

あなたのInsertCommandとは何ですか?

また、あなたがれるAcceptChangesを呼び出す場合AcceptChanges()

+0

INSERT INTO Vehicles(車両番号、車両製造、走行時間、運転時間、トラック#1シリアル番号、トラック#2シリアル番号、トラック#3シリアル番号)値(?、?、?、? 、?、?、?)この2行を削除した後、私は構文の例外を取得します。 – Bjorkson

+0

あなたは例外を投稿できますか? – TalentTuner

+0

INSERT INTO文の構文エラーです。あまり有益ではありません。私はbeforを頼んだと私は特別な文字についてのリプレイを持っているforparadoxテーブルは( "")とqutedする必要がありますが、私は他の問題を持っているSQLコマンドラインで試したとき:http://stackoverflow.com/questions/4366988/problem- with-insert-query-to-paradox-table-using-c – Bjorkson

0

削除コールを更新するためには何もありませんので、変更された行がありませんので、DataTableのすべての変更が受け入れられる

dsRetrievedData.Tables[0].AcceptChanges(); 
dsRetrievedData.AcceptChanges(); 

これらの行を削除した後にしてみてください:

dsRetrievedData.Tables[0].AcceptChanges(); 
dsRetrievedData.AcceptChanges(); 

According to MSDN

この データセットが読み込まれて以降、またはAcceptChangesが だったときに に変更されたすべての変更をコミットします。

これは、新しく追加された行をnot newとマークすることを意味します。

関連する問題