简体   繁体   中英

Conversion failed when converting the varchar value '@a' to data type int

I'm trying to update a column in SQL but I get this Error..

Code:

SqlConnection cn = new SqlConnection("CONNECTION STRING");
            SqlCommand com = new SqlCommand("update details set Available='Yes' where License='@a'", cn);
            com.Parameters.AddWithValue("@a", num);
            cn.Open();
            com.ExecuteNonQuery();
            cn.Close();

Remove the single quotes from around the @a

SqlConnection cn = new SqlConnection("CONNECTION STRING");
            SqlCommand com = new SqlCommand("update details set Available='Yes' where License=@a", cn);
            com.Parameters.AddWithValue("@a", num);
            cn.Open();
            com.ExecuteNonQuery();
            cn.Close();

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