简体   繁体   中英

SQL query does not update table

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM