Cannot write to a Microsoft Access file using SQL (OLEDB) C# -


i understand may considered duplicate question, @ impasse , not know doing wrong, need help. duplicate question said use oledb in order write microsoft access file, before using sql connection accomplish task. far can tell there no syntax, logic, or runtime errors , visual studios doesnt have issue either.

when run code , go add new entry microsoft access database table, says worked, when go , @ file there nothing there. please me, have goe through links, web pages, search engines, , dont know wrong. love learn wrong , how fix wont ever have ask again.

currently college student , working on team assignment. our task, create window take input user , add entry microsoft access file if sql database.

the issue having trying add new entry local microsoft access file under table named artist. have connected actual sql server before , no 1 else in group has, worse no 1 has done using microsoft access file on our pc either.

i have added database (microsoft access file) in visual studios using database configuration wizard. @ first using straight sql , told need use oledb in order this. have implemented in code , reason still cannot work. if can give me hand , tell me doing wrong, appreciate it.

details believe important me:

the name of table attempting write new entry to: artist

name of microsoft access file: kays.accdb

location of microsoft access file: c:\kaydb\kays.accdb (local machine)

once again appreciate can give me. curious why code not working, please me understand.

my code follows:

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.data.oledb;  namespace kay { public partial class kay_green : form {      string username,fname, mname, lname, streetaddress, city, phonenumber, emailaddress, zipcode, taxidnummber, state;      string[,] sqltable = new string[0, 10];      public kay_green()     {         initializecomponent();     }      private void btnsave_click(object sender, eventargs e)     {//save button          /*upon clicking save button, gather info , save temp array.           send sql database.*/          /*the order of data in array same order in sql table.*/          fname = tbfirstname.text;         mname = tbmiddleinitial.text;         lname = tblastname.text;         streetaddress = tbstreet.text;         city = tbcity.text;         state = cbstate.text;         phonenumber = tbphonenumber.text;         emailaddress = tbemailaddress.text;         zipcode = tbzipcode.text;         taxidnummber = tbtaxid.text;         username = tbusername.text;          /*sqltable[0,0] = taxidnummber;         sqltable[0,1] = fname;         sqltable[0,2] = mname;         sqltable[0,3] = lname;         sqltable[0,4] = streetaddress;         sqltable[0,5] = city;         sqltable[0,6] = state;         sqltable[0,7] = zipcode;         sqltable[0,8] = phonenumber;         sqltable[0,9] = emailaddress;*/            /*below details sql connection*/          string connectstring="provider=microsoft.ace.oledb.12.0;data source=c:\\kaydb\\kays.accdb";         oledbconnection connection=new oledbconnection(connectstring);         oledbcommand command;         oledbdataadapter adapter;         datatable dt = new datatable();           string sql ="insert artist values ('" + taxidnummber + "','"              + emailaddress + "','" + fname + "','" + mname + "','"             + lname + "','" + phonenumber+"','"+ username + "','"              + streetaddress + "','" + city + "','" +state+ "','"              + zipcode + "')";            try         {              connection.open();              command = new oledbcommand(sql, connection);              messagebox.show("connection open , data added table! ");               connection.close();         }         catch (exception ex)         {             messagebox.show("can not open connection ! " + ex.stacktrace.tostring());          }         /*above details sql connection*/      }      private void btncancel_click(object sender, eventargs e)     {//cancel button         tbcity.clear();         tbemailaddress.clear();         tbfirstname.clear();         tblastname.clear();         tbmiddleinitial.clear();         tbphonenumber.clear();         tbstreet.clear();         tbtaxid.clear();         tbzipcode.clear();         tbusername.clear();          close();//go switchboard here       }      private void btnclear_click(object sender, eventargs e)     {//clear button          tbcity.clear();         tbemailaddress.clear();         tbfirstname.clear();         tblastname.clear();         tbmiddleinitial.clear();         tbphonenumber.clear();         tbstreet.clear();         tbtaxid.clear();         tbzipcode.clear();         tbusername.clear();     }   } 

}

this code

command = new oledbcommand(sql, connection); 

sets command not run it

you need run afterwards:

command.executenonquery(); 

this has nothing connection strings


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -