Reputation: 33
I have got an UPDATE
query, what works well when I execute it in MS Managment Studio.
But if I try execute this query from my c# app, it executes without any exceptions, but does not update the table. Connection string is right.
This is the way I do it:
int contractId = 2
con.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\tst.mdf;Integrated Security=True;Connect Timeout=30";
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "update аренды set datetime_возврата=GETDATE() where id_договора=@contractId";
cmd.Parameters.Add("@contract_id", SqlDbType.Int, 4).Value = contractId;
cmd.ExecuteNonQuery();
What can be wrong?
Upvotes: 0
Views: 250
Reputation: 39966
If your c# code executes without any exceptions, it updates the database too, but please note you are used AttachDbFilename=|DataDirectory|\tst.mdf
in your ConnectionString
means the database that is updated is located in the sub-folder BIN\DEBUG
folder of your project. If you want to see the updated data just attach the database located in the bin/debug
folder in SSMS.
Also as Steve mentioned in comments, for more details read this post.
Upvotes: 1