|
-
Jan 10th, 2003, 01:09 AM
#1
Thread Starter
Junior Member
Error! Error! Error!
I'm getting this error message:
An unhandled exception of type 'System.InvalidCastException' occurred in system.windows.forms.dll
Additional information: Object cannot be cast from DBNull to other types.
This occurs when I click on the add new record button on the form on which I have check box controls bound to the dataset. I've realised that this maily happens because the fields in the database are null. In the database, the field type is 'bit'. I'm using SQL Server 2000. I tried setting the default values to zero in the database but still problem is not resolved. Somebody pls help. I'm stuck.
-
Jan 10th, 2003, 01:21 AM
#2
What is the select statement for the bind?
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Jan 10th, 2003, 02:35 AM
#3
Registered User
Try setting the default value in the dataset, something like.....
Code:
DataSet11.Table3.T1Column.DefaultValue = 0
-
Jan 10th, 2003, 03:39 AM
#4
Thread Starter
Junior Member
Here is my binding code
Dim da as New SqlDataAdapter("SELECT * FROM Customers", cnConnection)
Dim CMB as New SqlCommandBuilder(da)
Dim ds as New DataSet
da.Fill(ds)
chkApproved.Databindings.Add("Checked", ds.Tables( 0), "Approved")
........
On btnAddNewClick
me.bindingcontext(ds.tables(0)).Addnew
'Immediately, I get an error
I've just tried setting a default value but i still get the same error message, unless I've put the statement at the wrong place (just before the bind statement)
-
Mar 20th, 2004, 05:59 PM
#5
Lively Member
The problem is caused from binding certain types of controls, which can't display DBNull values properly, to the dataset. Two examples are the DateTimePicker, and the Checkbox. Here is an MSDN article that describes the problem:
http://support.microsoft.com/default.aspx?scid=kb;en-us;313513
I was having the same error and found that in my case, it was a Checkbox. I didn't use the solution provided in the MSDN article. I just made sure that the field in the dataset that the checkbox was bound to was not null before doing the "resumebinding" command on the binding context object (or in your case, AddNew).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|