locked
strange GUID does not allow null problem! RRS feed

  • Question

  • I have created a mobile form with .NET Compact Framework 2.0, and then I want to insert a new record into sdf db from this form and update back to sdf database through dataset. Because the tabe has a date time column and a guid column, and I set both of them do not allow null. When user wants to insert a new record they have to click a botton called "New", there i write code to generate the datetime and guid, after that I want to save this record back to sdf database. So I create another botton called "Save".The code is like below:

     

    botton "New":

    BindingSource.AddNew()

    DateTextBox.Text = DateTime.Now

    RowguidTextBox.Text = Guid.NewGuid.ToString

     

    botton "Save":

    BindingSource.EndEdit()

    TableAdapter.Update(DataSet.tabel1)

     

    After I click "New" the new datatime and new guid have been generated and I can see them on the form and I fill in everything else, But when I click "Save", there is an error"Column 'rowguid' does not allow nulls." I check the rowguid again and I can see it's updated. the Save botton code is from the a sample reference on MSDN:

    http://msdn2.microsoft.com/en-us/library/es6f6ht5.aspx

     

    Any idea will be appreciated

     

    Best regards,

     

     

     

     

    Monday, January 21, 2008 12:45 PM

Answers

  • Hi there,

     

    Thanks for your information. I managed to find out the problem. The prepared insert statement on table adapter missed a parameter for the GUID column. Somehow it's a little strange as it was generated automatically.

     

    By the way, the error occurred when it ran to EndEdit and the tableadapter.update line is needed because it uses prepared update statement from the table adapter to update the sdf db. And if there is no other user defined sql query which will be used to update the table in the sdf db, this one will do. Othewise db will not be updated.

     

    Thanks again

     

     

    Friday, January 25, 2008 3:25 AM

All replies

  • Hi, Jes

     

    >>BindingSource.EndEdit()

    >>TableAdapter.Update(DataSet.tabel1)

     

    After you've called the BindingSource.EndEdit, the underlying data table will be updated, so the second line is not needed. Comment the second line and have a try.

     

    If that does not work,

    1. could you confirm the actual data in sdf file is updated already?

    2. Which line of code the error was thrown at?

    3. Other information you think is necessary.

     

    Best Regards

    Chunsheng Tang

    Wednesday, January 23, 2008 7:29 AM
  • Hi there,

     

    Thanks for your information. I managed to find out the problem. The prepared insert statement on table adapter missed a parameter for the GUID column. Somehow it's a little strange as it was generated automatically.

     

    By the way, the error occurred when it ran to EndEdit and the tableadapter.update line is needed because it uses prepared update statement from the table adapter to update the sdf db. And if there is no other user defined sql query which will be used to update the table in the sdf db, this one will do. Othewise db will not be updated.

     

    Thanks again

     

     

    Friday, January 25, 2008 3:25 AM
  • Workarround... Use the option "generate stored procedures" for the table adapter, use a default value for the GUI field (you can use the "00000000-0000-0000-0000-000000000000") and modify the INSERT PROCEDURE so that it doesn't has the @GUI param, but add this two lines instead:

    DECLARE @GUI uniqueidentifier;
    SET @GUI = newid();

    Sunday, January 3, 2010 11:58 PM