I’m trying to insert records into a table via a sql management studio and insert command verses the website’s web form.
INSERT INTO [dbo].[Records] ([tp_ID], [Offense_ID], [LLO_ID], [LLLA], [SSN], [LastName], [FirstName], [MI], [Title], [Grade], [Organization], [BranchOfService], [Category], [DateCategory], [IsHoldover], [IsHoldoverDate])
VALUES (60033, N'E', 17, NULL, N'222-12-0222', N'SINGER', N'Te ', N'Y', NULL, N'SrA', N'703 Airbase', N'FORCE', NULL, NULL)
Although when I go to the website and try to view the record I recieve the following error message:
System.InvalidCastException: Conversion from type ‘DBNull’ to type ‘Integer’ is not valid.
Line 349:ckIsHoldOver.Checked = (CInt(rdr("IsHoldover")) = -1)
—vb in the code behind that caputures the field data if i create a record through the web form—
.Parameters.AddWithValue("@IsHoldover", ckIsHoldOver.Checked)
rdr("IsHoldover")isNULL, therefore when converting to integer usingCInt(), this is causing an exception.You can either change your
INSERTstatement to insert aNon-NULLbitvalue (1or0), or change your VB code to take into account this nullable field: