473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

DataView and Bindings question

I created a tabbed app that has over a dozen checkboxes on the second
tab. When I add a new record thru dataview, and click on the secodn
tab I get and error Object cannot be cast from other datatype DBNull.

Here is my code for creating my dataview:
try
{
da.Fill(ds);
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
dt = ds.Tables[0];
SqlCommandBuilder cb = new SqlCommandBuilder(da);
dv.Table = dt;

cm = (CurrencyManager)this.BindingContext[dv];

Then I set my bindings:

this.chkbOperationsRpt.DataBindings.Add("Checked", dv,
"OperationsReport");
this.chkbDrugTask.DataBindings.Add("Checked", dv, "DrugTaskForce");
this.chkbCADFire.DataBindings.Add("Checked", dv, "CADFire");
this.chkbNCIC.DataBindings.Add("Checked", dv, "E911NCIC");
Then I add new record:
try
{
dv.RowFilter = string.Empty;
cm.AddNew();
cm.Refresh();
cm.EndCurrentEdit();
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
I've got my database set where these fields do not allow nulls and the
default value is 0.

So where do I check to see if there are nulls or how can I fix this?

Thanks
Tom

Apr 12 '06 #1
2 1282
the best way to do this is to use a strongly typed dataset. if you can't
afford to you, you can always use the IsNull("name of field") property to
test. However it seems that this is not the problem you are experiencing
since your query forbids nulls and you are getting a null on a databind. It
stands to reason that the null is coming from outside the query if i
understand you correctly.
btw don't catch exception, that's bad. Try formatexception or some other
more specific exception.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"tawright915" <ta*********@yahoo.com> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com...
I created a tabbed app that has over a dozen checkboxes on the second
tab. When I add a new record thru dataview, and click on the secodn
tab I get and error Object cannot be cast from other datatype DBNull.

Here is my code for creating my dataview:
try
{
da.Fill(ds);
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
dt = ds.Tables[0];
SqlCommandBuilder cb = new SqlCommandBuilder(da);
dv.Table = dt;

cm = (CurrencyManager)this.BindingContext[dv];

Then I set my bindings:

this.chkbOperationsRpt.DataBindings.Add("Checked", dv,
"OperationsReport");
this.chkbDrugTask.DataBindings.Add("Checked", dv, "DrugTaskForce");
this.chkbCADFire.DataBindings.Add("Checked", dv, "CADFire");
this.chkbNCIC.DataBindings.Add("Checked", dv, "E911NCIC");
Then I add new record:
try
{
dv.RowFilter = string.Empty;
cm.AddNew();
cm.Refresh();
cm.EndCurrentEdit();
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
I've got my database set where these fields do not allow nulls and the
default value is 0.

So where do I check to see if there are nulls or how can I fix this?

Thanks
Tom

Apr 12 '06 #2
There were some nulls in those fields in SQL, but I removed them and
set the default value of 0. However when do an AddNew record from the
currency manager and then a refresh I still get the error. How can I
make it so that zeros are put in place as the default value.

Can you give me some more info on strongly type datasets. An example of
one field would be great.

Thanks
Tom

Apr 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steven C | last post by:
Hi, can any one help with this frustrating problem. I have a dataset filled from a Jet database via a paramaterised query. I dynamically bind each control to a dataview each time a next /...
14
by: Barney | last post by:
How can I populate a textbox from a dataview? I have a dataset i'm filtering on and i want to populate several textboxes based on that filter. How can i get that to work? I've tried: ...
1
by: Tony Papadimitriou | last post by:
Hi, Here's a short description of a problem that took me a couple of days to bypass (not solve): I update a table thru a dataview (or dataset, no difference in behavior for this problem) and...
10
by: Marc R. | last post by:
Hi all, I edit records using a form that have multiple control bind on Dataview, But I don't want to update right always to database, I would like to delay until all Changes (add all new...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.