Probably, you should swap field name (abcd) and its value (25.04.2017):
// Keep query
// 1. Readable: @
// 2. Paramterized: @prm_date, @prm_id
// 3. Formattable: {abcd} (string interpolation)
string sql =
$@"update attendance
set {abcd} = @prm_date -- field = value
where std_id = @prm_id";
//DONE: wrap IDisposable into using
using (var cmd = System.Data.SqlClient.SqlCommand(sql, con)) {
// Parametrize query
//TODO: AddWithValue is not the best choice, turn into Add + Actual db type
cmd.Parameters.AddWithValue("@prm_date", new DateTime(2017, 4, 25));
cmd.Parameters.AddWithValue("@prm_id", b);
cmd.ExecuteNonQuery();
}
Edit: In (for me very improbable) case that '25.04.2017' is a field name and abcd is its value:
string sql =
$@"update attendance
set [25.04.2017] = @prm_abcd -- eerie field with '25.04.2017' name
where std_id = @prm_id";
//DONE: wrap IDisposable into using
using (var cmd = System.Data.SqlClient.SqlCommand(sql, con)) {
// Parametrize query
//TODO: AddWithValue is not the best choice, turn into Add + Actual db type
cmd.Parameters.AddWithValue("@prm_abcd", abcd);
cmd.Parameters.AddWithValue("@prm_id", b);
cmd.ExecuteNonQuery();
}
add column dyanmically with the Data time now- seriously now, don't do that!