Insert a row containing NULL GUID

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Microsoft SQL Server
Post Reply
TEMRUS
Posts: 6
Joined: Tue 01 Feb 2011 12:06

Insert a row containing NULL GUID

Post by TEMRUS » Mon 19 Sep 2011 14:18

Hi!

How to insert a record in my DB that contain NULL ID GUID field?

Code: Select all

INSERT INTO tPodrazd 
(PodrazdID, PodrazdVCNum, PodrazdPolnNazv, PodrazdNazv, PodrazdComm, PodrazdIsDel, PodrazdRank) 
VALUES 
(NEWID(), @PodrazdVCNum, @PodrazdPolnNazv, @PodrazdNazv, @PodrazdComm, 0, 0)
When executing this code

Code: Select all

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            dataLink.AddNew();
            DialogResult res = new fPodrazdEd().ShowDialog();

            if (res == DialogResult.OK)
            {
                dataLink.EndEdit();
            }
            else if (res == DialogResult.Cancel)
            {
                dataLink.CancelEdit();
            }
        }
an exception is rised:
System.Data.NoNullAllowedException is not processed.
Message="PodrazdID" field can not contain nulls.

I tried to change AllowDBNulls parameter of PodrazdID datacolumn in the DataSet schema, but it still not working.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Insert a row containing NULL GUID

Post by Shalex » Thu 22 Sep 2011 09:14

TEMRUS wrote:I tried to change AllowDBNulls parameter of PodrazdID datacolumn
This is correct (AllowDBNull=True). Here are additional steps:
1. Remove the primary key constraint from the Constraints colletion of the corresponding SqlDataTable via its Properties window.
2. Right click on SqlDataTable > Configure Data Table > the Command Generator tab > press Get Table Fields > select Refreshing for your PodrazdID column > select the "With refresh SQL" options in the Options section for insert and update commands > press Generate Commands > press OK.

Post Reply