1

I am getting an error msg when attempting to update a record from asp.net into a SQL database. The only boolean value being updated is:

cmdAddUser.Parameters.Add(new SqlParameter("@Active", SqlDbType.Bit));
cmdAddUser.Parameters["@Active"].Value = 
    Convert.ToBoolean(cbAddUserActiveUser.Checked);

The datatype for @Active in the database is "bit". Any ideas?

user279521
  • 4,779
  • 21
  • 78
  • 109
  • @user279521: You aren't really indicating what error you are getting. Try posting the exception information that you are getting so we can determine if it is a parse issue (on the call to ToBoolean) or something on the database side. – casperOne Jun 28 '10 at 15:55
  • "Failed to convert parameter value from a String to a Boolean." is the error message. – user279521 Jun 28 '10 at 15:56
  • Wild guess, but try `Convert.ToBoolean(cbAddUserActiveUser.Checked.ToString());` – Jason Evans Jun 28 '10 at 15:58
  • @Jason.... No luck.... Same error – user279521 Jun 28 '10 at 16:01
  • What about trying without the convert.toboolean? Isn't .checked already a boolean value? – Tommy Jun 28 '10 at 16:04
  • I think casperOne is asking for the stack trace so we can see what is causing the error - the Convert.ToBoolean or the .Value = x. – Adam Fox Jun 28 '10 at 16:06
  • From the help "Bit - Boolean. An unsigned numeric value that can be 0, 1, or null (Nothing in Visual Basic)." – Adam Fox Jun 28 '10 at 16:13

1 Answers1

2

Long shot - have you got another parameter that is set as a string but is a bit column in the actual table?

harriyott
  • 10,505
  • 10
  • 64
  • 103