problem with database connection

sql server 2005 tables not getting updated permanently

Page 1 of 1

1 Replies - 602 Views - Last Post: 20 March 2010 - 09:03 AM Rate Topic: -----

#1 avan123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-March 10

problem with database connection

Posted 20 March 2010 - 03:19 AM

hi.........
i hav a problem updating, inserting and deleting records from sql server database connected tomy c# appliction using Visual studio 2005
my queries run perfectly but the tables get updated for the running instance only, when i close the application and run it again the database tables are not affected at all.........
what may be the problem ???



this is my code to add new item to database table on button click event...




private void btn_add_Click(object sender, EventArgs e)
{
con1.Open();
float tar = float.Parse(txt_serTariff.Text);

pan_newService.Visible = true;
SqlCommand comm1 = new SqlCommand("insert into service(name,tariff) values ('" + txt_serName.Text + "','" + tar + "') ", con1);
comm1.ExecuteScalar();
MessageBox.Show("New service added ");
con1.Close();

}

Is This A Good Question/Topic? 0
  • +

Replies To: problem with database connection

#2 Sn0wBum  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 178
  • Joined: 04-February 10

Re: problem with database connection

Posted 20 March 2010 - 09:03 AM

Have you tried using comm1.ExecuteNonQuery() ?

Here is an MSDN reference to SqlCommand.ExecuteNonQuery that may help you to better understand.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1