New to C#


hi everyone.  this first experience creating mvc type application in c# asp ui , i'm having trouble data access.  the strangest part wasn't having trouble , seems no reason, insert statements have stopped working.  i'm not sure code helpful if more on user controls or controller methods, ask.  i'm not looking criticism or critique, need else blantant syntax errors missing.  i assure file path correct database.  if wants me send them whole visualstudio solution can too.  here's part of code throwing exceptions.

thanks willing attempt solution here. have learned lot these forums , first post. apologize if in wrong forum.

      public string insertnewemployee(employee vempl)      {                    bool isinserted = false;        oledbconnection curconn = new oledbconnection();              curconn.connectionstring = "provider=microsoft.ace.oledb.12.0;data source=c:\\new\\enrollments.accdb";        string ssql = "insert employees (empl_fname, empl_lname, empl_addr1, empl_addr2, empl_city, empl_state, empl_zip, empl_phone, empl_planid, empl_deptid) values ('"           + vempl.empl_fname + "','" + vempl.empl_lname + "','"           + vempl.empl_addr1 + "', '" + vempl.empl_addr2 + "','"           + vempl.empl_city + "','" + vempl.empl_state + "','"           + vempl.empl_zip + "'," + convert.toint32(vempl.empl_phone) + ","           + convert.toint32(vempl.empl_planid) + "," + convert.toint32(vempl.empl_deptid) + ")";              oledbcommand mycom = new oledbcommand(ssql, curconn);              try         {        curconn.open();        //executescalar throws exception , runs catch statement        mycom.executescalar();              ssql = string.empty;        ssql = "select empid employees empl_fname = '" + vempl.empl_fname + "' , empl_lname = '" + vempl.empl_lname + "'";        mycom = new oledbcommand(ssql, curconn);        oledbdatareader reader = mycom.executereader();          while (reader.read())        {          vempl.empl_id = string.format("{0}", reader[0]);        }                curconn.close();        isinserted = true;        }      catch(exception e)         {        isinserted = false;        }      finally        {        curconn.close();        }        return vempl.empl_id;      }  

 

this code used select database , populate dropdown lists. code works causing more confusion:

      public dataset getinscoids()      {        dataset dsinscoids = new dataset();        oledbconnection curconn = new oledbconnection();        curconn.connectionstring = "provider=microsoft.ace.oledb.12.0;data source=c:\\new\\enrollments.accdb";        string ssql = "select * insurancecompany";        oledbcommand mycom = new oledbcommand(ssql, curconn);        oledbdataadapter dataadapter = new oledbdataadapter(mycom.commandtext, curconn);                try        {          curconn.open();          mycom.executereader();          dataadapter.fill(dsinscoids, "insurancecompany");          curconn.close();          return dsinscoids;        }        catch (exception e)        {          return dsinscoids;        }        finally        {          curconn.close();        }      }  



um, also, looks have many tic marks in sql.

 

  string ssql = "insert insurancecompany (insco_name, insco_description) values ('"
     + vinsco.insco_name + "','" + vinsco.insco_description + "')'";

 

put breakpoint here:

mycom.executescalar();

then, hover on mycom object or go quickwatch , @ string value in 'commandtext'.  if sql correct, should able paste commandtext value in mycom access query , vice versa.  make sense?

 
please vote &/or "mark answer" if post helpful you. , happy coding :d


Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'