nulls in datasets

  • Thread starter Thread starter Nathan Kovac
  • Start date Start date
N

Nathan Kovac

A recent project I am working on is basically an interface to an sql
database. I have not done too much with sql databases from the c# area so I
am having to learn a few things. I am creating a simple example project
which is a simple form which interfaces a database table. It has a dropdown
to select which record to choose and several different data fields on each
selection. Thanks to MajorTom I was able to get this portion working great.

I have also gotten fields to update the sql server data source when I move
on to the next record.

My next goal is to insert a new record and allow it to be written back to
sql server. I discovered I can do this by adding a new row to the dataset.
But to add this new row I need to specify default values. Several of my
database fields are defaulted null. In this particular example I have a
list of tickets, each tickets has a project and subproject. The
subprojectID isn't required and therefore needs to default to null. But
null isn't an int data type. How do I do this or am I going about this the
wrong way?

Thanks,
Nathan
 
Nathan said:
My next goal is to insert a new record and allow it to be written
back to sql server. I discovered I can do this by adding a new row
to the dataset. But to add this new row I need to specify default
values. Several of my database fields are defaulted null. In this
particular example I have a list of tickets, each tickets has a
project and subproject. The subprojectID isn't required and
therefore needs to default to null. But null isn't an int data type.
How do I do this or am I going about this the wrong way?

If the field is defined is nullable in the database then passing
DBNull.Value should work.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
 
The Database table I was pulling from does allow nulls. It was used to
generate the dataset, but the dataset doesn't seem to allow a DBnull. Here
is my line...

ticketDataSet1.Ticket.AddTicketRow(1, Session.Instance.employeeID, 1, 1,
DBNull.Value, 1, DateTime.Today, DateTime.Today, 0, "");

Do I need to make some change i the schema to allow this null?
This is a portion of the xml schema.
<xs:element name="Ticket">

<xs:complexType>

<xs:sequence>

<xs:element name="TicketID" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:int" />

<xs:element name="TicketStatusID" type="xs:int" minOccurs="0" />

<xs:element name="UserID" type="xs:int" minOccurs="0" />

<xs:element name="ClientID" type="xs:int" minOccurs="0" />

<xs:element name="ProjectID" type="xs:int" minOccurs="0" />

<xs:element name="SubprojectID" type="xs:int" minOccurs="0" />

<xs:element name="taskID" type="xs:int" minOccurs="0" />

<xs:element name="start" type="xs:dateTime" minOccurs="0" />

<xs:element name="stop" type="xs:dateTime" minOccurs="0" />

<xs:element name="elapsed" type="xs:int" minOccurs="0" />

<xs:element name="Descr" type="xs:string" minOccurs="0" />

</xs:sequence>

</xs:complexType>

</xs:element>
 
Back
Top