The best way to explain this is with code:
byte roominspiration = 0;
query = "SELECT room_inspiration FROM Room WHERE room_id = @room_id); SELECT SCOPE_IDENTITY();";
using (sqlConnection1)
{
using (SqlCommand cmd = new SqlCommand(query, sqlConnection1))
{
cmd.Parameters.Add("@room_id", System.Data.SqlDbType.Int);
cmd.Parameters["@room_id"].Value = roomid;
sqlConnection1.Open();
if (cmd.ExecuteScalar() != null)
{
roominspiration = (byte)cmd.ExecuteScalar();
}
}
}
All I’m trying to do is update the value of ‘roominspiration’ to whatever the value of that record in the database is. The field in the database is a bit datatype with a default value of 0. It is always set correctly, so this shouldn’t an issue in it returning null.
Can anyone spot what I’m doing wrong, or if there’s a better way to do what I’m doing. My C# skills aren’t too good, but I’m trying to learn!
Thanks folks!
I think you want to use the
bool.NET data type here.So,