Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my database update code
when i run this no errors but database not updated still same vales


C#
string  c_time= DateTime.Now.ToString("HH:mm:ss tt");
string  c_date= DateTime.Today.ToString("dd-MM-yyyy");

using (SqlConnection conn = new SqlConnection(@"Data Source=MCK-PC\MCKSQL;Initial Catalog=my_db;Integrated Security=True"))
 {
   SqlCommand newCmd = new SqlCommand(@"UPDATE emp SET last_act_date=@last_act_date , last_act_time=@last_act_time WHERE Card_no=@Card_no;", conn);

   newCmd.Parameters.AddWithValue("@last_act_date", c_date);
   newCmd.Parameters.AddWithValue("@last_act_time", c_time);
   newCmd.Parameters.AddWithValue("@Card_no", card_no_input.ToString());

   ConnectionState state = conn.State;
   if (state == ConnectionState.Closed)
     {
       newCmd.Connection.Open();
       newCmd.ExecuteNonQuery();
       newCmd.Connection.Close();
     }

   else
     {
       newCmd.ExecuteNonQuery();
       newCmd.Connection.Close();
     }

 }


THANK IN ADVANCE!
Posted

1 solution

Check card_no_input - it sounds like it's an input of some kind, so there is a goods chance that you want it's Text property rather than calling ToString.

If it is a TextBox for example, your query will be trying t to update all records where the card number is "System.Forms.TextBox" or similar
 
Share this answer
 
Comments
[no name] 9-Aug-13 13:41pm    
Nice
Manoj Chamikara 9-Aug-13 13:45pm    
yes dude card_no_input is name of the textbox
i change this
newCmd.Parameters.AddWithValue("@Card_no", card_no_input.ToString());

to this
newCmd.Parameters.AddWithValue("@Card_no", card_no_input.Text);

now it's works prefect and it's also update the database
THANKS A LOT your quick response
OriginalGriff 9-Aug-13 14:00pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900