c# - ExecuteNonQuery of insert function fired successfully but database doesn't update -
i seek insert info database, operations done database not update after sql query executed. windows based application. set connection string in app.config
file.
when run application code. , insert info show me msg "data inserted", when check database there no info updated in database.... give me solution.
i utilize visual studio 2013 , sql server 2012.
here code:
namespace sample { public partial class form1 : form { public form1() { initializecomponent(); } private void button1_click(object sender, eventargs e) { seek { sqlconnection sqlcon = new sqlconnection(configurationmanager.connectionstrings["cons"].connectionstring.tostring()); sqlcon.open(); string str = "insert tab(name,pwd) values('" + textbox1.text.tostring() + "','" + textbox2.text.tostring() + "')"; sqlcommand cmd = new sqlcommand(str, sqlcon); cmd.executenonquery(); messagebox.show("data inserted"); cmd.clone(); } catch(exception e) { messagebox.show("no info inserted"); } } } }
app.config
<configuration> <connectionstrings> <add name="cons" connectionstring="data source=(localdb)\v11.0;attachdbfilename='|datadirectory|\database1.mdf';integrated security=true"/> </connectionstrings> </configuration>
hey solve problem myself
i replace total path in connection string (|datadirectory|\database.mdf).... this
<configuration> <connectionstrings> <add name="cons" connectionstring="data source=(localdb)\v11.0;attachdbfilename='c:\users\dhaval\documents\visual studio 2013\projects\sample\sample\database.mdf';integrated security=true"/> </connectionstrings> </configuration>
so connection string access right database of application.. not(.\bin\debug) "database.mdf" file..
c# database sql-server-2012 sqlconnection windows-applications
No comments:
Post a Comment