Sam2

I am trying to change the NullValue property of a field to return a null if the field is null. Of course, this causes the followng error msg even though the underlying table allows null values:

"For columns not defined as System.String, the only valid value is (Throw exception)."

I see where others have had the same problem:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=436677&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=935074&SiteID=1

The preceeding threads are marked as "Answered" however the only answer I see is the acknowlgement of a bug. Has this been fixed Where is the documentation

Thanks



Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Ken Tucker

I believe there were some fixes to the dataset designer in Visual Studio 2005 service pack 1




Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Sam2

I'm running sp1.

Thanks,

Sam





Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Sam2

Can anyone tell me if this bug/limitation exists in VS (i.e. not VS Express).

Thanks





Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Eijeriks

This is a problem in all versions off vs it seems, i am trying to figure this out in vs 2005 proffesional




Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Sam2

Actually I'm a little concerned by the fact that this does not work and nobody knows or cares. One would think a glitch on a low level component like this would have been identified and fixed long ago. I am still fairly new to ADO and I want to learn to use the tools provided by VS to build things as quickly and efficiently as possbile. The silence regarding this issue is deafening - it makes me wonder if a) I'm not seeing an obvious fix, or b) no one has embraced this technology. Is the concept of tableadapters still used in Orcas Should I jusk skip this and move forward

Thanks





Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Ken Tucker

I am not seeing this problem on my machine. What kind of database are you using TableAdapters are still around in orcas.




Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Sam2

Database is local SQL Server database.

Are you able to set the NullValue property for a datetime column to something other than throw exception

I get this error msg: For columns not defined as System.String, the only valid value is (Throw exception).

My code is a simple foreach loop:

Code Snippet

foreach (EDataSet.JobsRow jobRow in this.eDataSet.Jobs)

{

if (jobRow.RowState == DataRowState.Added)

this.jobsTableAdapter.InsertJob(jobRow.JobName,jobRow.JobType <snip>

Which calles this code generated by vs

Code Snippet

[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]

public System.DateTime LastRunDate {

get {

try {

return ((global::System.DateTime)(this[this.tableJobs.LastRunDateColumn]));

}

catch (global::System.InvalidCastException e) {

throw new global::System.Data.StrongTypingException("The value for column \'LastRunDate\' in table \'Jobs\' is DBNull.", e);

}

the above code throws an error when the column is null.





Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Sam2

Great. It's broken in Orcas too. Sad



Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Ken Tucker

I do get an exception if I try and set the NullValue property for a date time column. You need to set the columns AllowDBNull property to true.

You need to check the IsColumnNameNull to see if the value is null before you try and get the value of datetime column

Code Snippet

NorthwindTableAdapters.OrdersTableAdapter ta = new NorthwindTableAdapters.OrdersTableAdapter();
Northwind.OrdersDataTable dt = new Northwind.OrdersDataTable();
ta.Fill(dt);

foreach (Northwind.OrdersRow dr in dt.Rows)
{
System.Diagnostics.Debug.WriteLine(dr.IsShippedDateNull() "Null" : dr.ShippedDate.ToShortDateString());
}






Re: Windows Forms Data Controls and Databinding tableadapter will not return null values

Sam2

>> You need to set the columns AllowDBNull property to true.

Already done.

Your code works. Thanks.

For those who want to use this with a datetime field here is what you have to do:

Code Snippet

Nullable<DateTime> nullDate = null;

foreach (EDataSet.JobsRow jobRow in this.eDataSet.Jobs)

{

if (jobRow.RowState == DataRowState.Added)

this.jobsTableAdapter.InsertJob(jobRow.JobName,jobRow.JobType,

jobRow.IsLastRunDateNull() nullDate : jobRow.LastRunDate, <snip>