Error inserting data from textbox to sql database in c# -
when try insert value textbox database, values not being updated in database. newly inserted rows temporarily available, after inserting when use select query rows, new rows available. when close solution , open again, newly insert rows gone. table in database explorer not updated.
here code.
string connectionstring = @"data source=.\sqlexpress;attachdbfilename=|datadirectory|\database1.mdf;integrated security=true;user instance=true"; string na = textbox1.text; int ag = int.parse(textbox2.text); string ci = textbox3.text; using (sqlconnection connection = new sqlconnection(connectionstring)) { using (sqlcommand insertcommand = connection.createcommand()) { insertcommand.commandtext = "insert address(name,age,city) values (@na,@ag,@ci)"; insertcommand.parameters.addwithvalue("@na", na); insertcommand.parameters.addwithvalue("@ag", ag); insertcommand.parameters.addwithvalue("@ci", ci); insertcommand.connection.open(); insertcommand.executenonquery(); insertcommand.connection.close(); messagebox.show("finish"); } //connection.close(); }
the table name "address" , has 3 fields name(varchar(50)),age(int),city(nchar(10)) please help.
you said "c:\users\thangamani\documents\visual studio 2010\projects\addressbook\addressbook\bin\debug\" in error. attaching local copy during debug.
now not copying database over, mdf file not exist, hence error.
change connection string access original database, not local copy (which not making anymore).
Comments
Post a Comment