working with windows forms
i m inserting values to database using executeNonQuery
on debugging its working but changes r not reflected to database
private void BtnCommit_Click(object sender, EventArgs e)
{//dekho
int amtwith = Convert.ToInt32(txtAmount.Text.Trim());
int bal = Balance() - amtwith;
con.Open();
SqlCommand cmd = new SqlCommand("update balance set bal=@bal where cardno=@cno", con);
cmd.Parameters.AddWithValue("@bal", bal);
cmd.Parameters.AddWithValue("@cno",this.CardNo);
cmd.ExecuteNonQuery();
balance is Rs." + bal);
con.Close();
}
Sam HobbsPosted Oct 31, 2009, 3:04 AM
Kirtan PatelPosted Oct 28, 2009, 9:38 AM
your code perfectly works fine its just your misunderstanding that its not writing to database
because when you press Run button of Visual Studio Visual Studio Creates New Database Copy of your Database and your
Inserted Values Goes in that temprary Created Database .
so when you again press Run Button of Application after Inserting First time .it again Overwrites Database With New Copy of Database .
Visual Studio Does this Because to Prevent spoile of database with temprary data. during debug time ..
..
If you Put Your Compiled Exe and Database File in Separate Folder It Will Work defenetly
All the Best :)
check "Do you like this answer" if it helped you :)