Connecting Tech Pros Worldwide Forums | Help | Site Map

How update data stored in database?

Newbie
 
Join Date: Sep 2009
Posts: 21
#1: Oct 5 '09
hi,

i am trying to update data stored in data base with following code i am able to show data from database but i can not able to update it.

Expand|Select|Wrap|Line Numbers
  1.  
  2. int Theme_ID = Convert.ToInt32(textBox1.Text);
  3.             string Theme_Name = textBox2.Text;
  4.             SqlCeConnection conn;
  5.  
  6.             string connstr = " Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "\\MyFirstDataBase.sdf;";Persist Security Info=False;";
  7.             conn = new SqlCeConnection(connstr);
  8.             conn.Open();
  9.  
  10.             SqlCeCommand cmd = new SqlCeCommand();
  11.             cmd.CommandText = "update Theme set Theme_Name=Theme_name where Theme_ID=Theme_ID ";
  12.  
  13.             cmd.Connection = conn;
  14.             cmd.Parameters.AddWithValue("Theme_ID", Theme_ID );
  15.             cmd.Parameters.AddWithValue("Theme_Name", Theme_Name);
  16.  
  17.             cmd.ExecuteNonQuery();
  18.             conn.Close();
  19.  
  20.  

the above code execute well but can not create any change in database.

markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Posts: 546
#2: Oct 5 '09

re: How update data stored in database?


I would assume your SQL is the problem.

Try it out manually 1st then see if it works
Reply