Access C# COM object that has been separated from its underlying RCW cannot be used -
i worked lot not solved problem. making program in c# access database.
i added new form , want update database form.
i getting id in form; gelenid = form1.id2;
this code. im getting error in 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]=@isim, [bolum]=@bolum, [yapilacak_is]=@yapis, [tarih]=@tarihim, [durum]=@durum [id]=@id"; 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 cover parameter komut.parameters.addwithvalue("@id", idm); komut.executenonquery(); baglanti.close(); komut.dispose();
i added komut command
oledbconnection baglanti = new oledbconnection("provider=microsoft.ace.oledb.12.0;data source=bakimveritabani.accdb"); oledbcommand komut = new oledbcommand();
i have 1 connection.
that problem, connection can not handle being opened , closed multiple times, should making new connection every time , disposing of using
statement.
using(oledbconnection baglanti = new oledbconnection("provider=microsoft.ace.oledb.12.0;data source=bakimveritabani.accdb") using(oledbcommand komut = new oledbcommand()) { 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]=@isim, [bolum]=@bolum, [yapilacak_is]=@yapis, [tarih]=@tarihim, [durum]=@durum [id]=@id"; 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 cover parameter komut.parameters.addwithvalue("@id", idm); komut.executenonquery(); }
Comments
Post a Comment