徹底的に検索しましたが、SQLステートメントSET
を使用して初期化した変数への列データへの方法を見つけることができませんでした。UPDATE
問題を引き起こしているコードは次のとおりです。
int maxId;
SqlConnection dataConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString) ;
SqlCommand dataCommand = new SqlCommand("select max(UserID) from Registration", dataConnection) ;
dataConnection.Open();
maxId = Convert.ToInt32(dataCommand.ExecuteScalar());
string Id = maxId.ToString();
// this next line is not working
SqlCommand _setvin = new SqlCommand("UPDATE Registration SET VIN=maxId , Voted=0 WHERE UserID=maxId", dataConnection);
_setvin.ExecuteNonQuery();
dataConnection.Close();
上記のコメント行を修正する方法を教えてください。