-1
我工作了很多,但沒有解決這個問題。我正在用access數據庫在c#中編寫一個程序。訪問已經從其底層RCW分離的C#COM對象不能使用
我添加了新的表單,我想用此表單更新數據庫。
我以另一種形式獲得id; gelenid = Form1.id2;
這是我的代碼。我在komut.ExecuteNonQuery()中得到錯誤;
isim = comboBox1.Text;
yapilacak_is = textBox1.Text.Trim();
bolum = comboBox2.Text.Trim();
tarih = monthCalendar1.SelectionRange.Start.ToShortDateString();
durum = comboBox3.Text;
int idm = Convert.ToInt32(gelenid);
baglanti.Open();
komut.Connection = baglanti;
komut.CommandText = @"UPDATE Bakim SET [Ad][email protected],
[Bolum][email protected],
[Yapilacak_Is][email protected],
[Tarih][email protected],
[Durum][email protected]
WHERE [Id][email protected]";
komut.Parameters.AddWithValue("@isim", isim);
komut.Parameters.AddWithValue("@yapis", yapilacak_is);
komut.Parameters.AddWithValue("@bolum", bolum);
komut.Parameters.AddWithValue("@tarih", tarih);
komut.Parameters.AddWithValue("@durum", durum);
// Moved after the Cover parameter
komut.Parameters.AddWithValue("@Id", idm);
komut.ExecuteNonQuery();
baglanti.Close();
komut.Dispose();
我加入komut用於命令
OleDbConnection的baglanti =新的OleDbConnection( 「提供者= Microsoft.ACE.Oledb.12.0;數據源= BakimVeritabani.accdb」); OleDbCommand komut = new OleDbCommand();
您需要顯示'komut'是如何創建的。此外,你真的應該使用'使用'塊,而不是調用'.Dispose()'和'.Close()'maunally。 –
OleDbConnection baglanti = new OleDbConnection(「Provider = Microsoft.ACE.Oledb.12.0; Data Source = BakimVeritabani.accdb」); OleDbCommand komut = new OleDbCommand(); Form1 frmAna =(Form1)System.Windows.Forms.Application.OpenForms [「Form1」]; –
永遠不要把代碼放在註釋中,它應該只在問題中進行並且格式正確。你還需要展示兩者如何相互關聯。在功能中創建baglanti還是您有一個連接,您繼續重複使用 –