sql - [C#]Doesn't insert in DB, does give a executenonquery of 1 -
i busy project in have insert data in compact sql db file created in visual studio 2010 express. every check says insert being done properly, 1 drawback, everytime check database no data inserted. tried:
checking command.executenonquery() result
i tried , catched.
i did direct sql insert , worked.
i checked connectionstate.
so out of ideas, hope guys can help.
oh, , code might of use:
private void butaddoilblend_click(object sender, eventargs e) { connecttodb connection = new connecttodb(); try { connection.connect.open(); string sqlcommand = "insert oilblendstable(oilblendsname, oilblendsdescription) values(@oilblendsname, @oilblendsdescription)"; using (sqlcecommand command = new sqlcecommand(sqlcommand, connection.connect)) { command.parameters.addwithvalue("@oilblendsname", tbnameoilblend.text); command.parameters.addwithvalue("@oilblendsdescription", tboilblenddescription.text); command.executenonquery(); int affectedrows = command.executenonquery(); messagebox.show(affectedrows.tostring()); } lblfinalword.text = "you added new blend named: " + tbnameoilblend.text; } catch (sqlexception ex) { messagebox.show(ex.message.tostring()); } catch (exception ex) { messagebox.show(ex.message.tostring()); } { connection.connect.close(); } }
copy always
means every time start debug application fresh copy of sdf file copied project directory
datadirectory
overwriting file there.
the datadirectory
in winforms app bin\debug.
inserts going database (bin\debug\oildb.sdf).
@ next run these inserts lost.
should use copy if newer
where |datadirectory|
visual studio - file properties
here supposing check missing data looking @ file stored in project directory through connection defined in server explorer window. check connection string
Comments
Post a Comment