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

R

Rob Dob

I am trying to set the NullValue within the Column properties of my Dataset
in VS2005. The DataType is a System.DateTime. and when I try and change it
from "(Throw Exception)" I get the following error:

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

The Datafield is a datetime that allows nulls, if I don't set this value
then when I try save changes to this field within my form I get it
complaining about not allowing DBNull for that field..



I am also having this same problem with DataType int where I also allow
nulls



any help would be appreciated.,
 
S

Steven Nagy

Hi Rob,

First, can we see the code where you are assigning your null to your
datarow?
Secondly, is the dataset a 'typed' dataset?
And finally, what database are you using?

Cheers,
Steven
 
R

Rob Dob

Hi,

I have a DateTimePicker Databound to Dataset datacolumn whicc allow nulls:

And before I call update on my tableadapter I do something like: where ( ordersCustomersRow ) is a view of two combined tables.
ordersRow.Permit_Date = ordersCustomersRow.Permit_Date;

I'm using MSSQL2005
 
M

Mel

I set it using parameters, something like


using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "Update Policys set ExpDate = @ExpDate where
primaryKey = @primaryKey";
cmd.Parameters.Add("@ExpDate", SqlDbType.DateTime).Value = DBNull.Value;
cmd.Parameters.Add("@primaryKey", SqlDbType.Int).Value = 100;
}
 
R

Rob Dob

Hi,
I set it using parameters, something like


using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "Update Policys set ExpDate = @ExpDate where
primaryKey = @primaryKey";
cmd.Parameters.Add("@ExpDate", SqlDbType.DateTime).Value =
DBNull.Value;
cmd.Parameters.Add("@primaryKey", SqlDbType.Int).Value = 100;
}

I would prefer to just set the value within my strongly typed dataset before
I call its TableAdaptersUpdate(), is this possible?

Thanks,
 
B

Bart Mermuys

Hi,
I have a DateTimePicker Databound to Dataset datacolumn whicc allow nulls:
And before I call update on my tableadapter I do something like: where
( ordersCustomersRow ) is a view of two combined tables.
ordersRow.Permit_Date = ordersCustomersRow.Permit_Date;

Try something like:

if ( ordersCustomersRow.IsPermit_DateNull() )
odersRow.SetPermit_DateNull()
else
ordersRow.Permit_Date = ordersCustomersRow.Permit_Date

Or simply untyped:

ordersRow["Permit_Date"] = ordersCustomerRow["Permit_Date"];

HTH,
Greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top