Reputation: 205
I have SQL2008R2 and it has data type of "bit" which has default value of "0". I have a option button for yes or no on the form (VS2012) and "No" is selected by default. I am getting this silly "Object reference not set to an instance of an object" when I try to insert the values into the table. This is what I have inside "try, catch, end try" block for the button.
Dim strPolice As String
strPolice = optPolice.SelectedValue.Trim()
If strPolice IsNot Nothing Then
PoliceDetailDS.InsertParameters("Police_Informed").DefaultValue = strPolice
End If
Upvotes: 0
Views: 159
Reputation: 205
Ok this is what I did. I reconfigured the datasource and selected * instead of each field. then change the code for this way.
If optPolice.SelectedValue = "Yes" Then
PoliceDetailDS.InsertParameters("Police_Informed").DefaultValue = True
Else
PoliceDetailDS.InsertParameters("Police_Informed").DefaultValue = False
End If
Thanks for all of your help.
Upvotes: 0
Reputation: 416131
If optPolice.SelectedValue IsNot Nothing Then
PoliceDetailDS.InsertParameters("Police_Informed").DefaultValue = optPolice.SelectedValue.Trim()
End If
Upvotes: 0
Reputation: 460278
I guess that optPolice.SelectedValue
is Nothing
, hence theres nothing selected.
If optPolice.SelectedValue IsNot Nothing Then
Dim strPolice = optPolice.SelectedValue.Trim()
PoliceDetailDS.InsertParameters("Police_Informed").DefaultValue = strPolice
End If
Upvotes: 1