none
_COMPlusExceptionCode = -532459699 RRS feed

  • Question

  •  

    Hello everyone,

    I am writting a c# software that reads and writes in a db trough an interface some data... I have problems with a guid field because I can't read and load a null field into an object and I also can't convert a empty string into guid or directly write it in a guid field. Can somebody plese help me?

    here is a piece of the code:

    else

    {

    SqlConnection rConnection = new SqlConnection(kConnString);

    SqlCommand rQrySqlCmd = new SqlCommand();

    rLibId = fData.rLibId;

    rLibrary = fData.rLibrary;

    rItem = fData.rItem;

    rItemCategory = fData.rItemCategory;

    rItemDescription = fData.rItemDescription;

    rItemObsolete = fData.rItemObsolete;

    rItemLN = fData.rItemLN;

    rItemBarCode = fData.rItemBarCode;

    rLibDicID = fData.rLibDicID;

    #region query

    string kQuery = "insert into libreg (rlibdictionary ,rlibitem ,rlibcategory ,rlibdescription ,rlibobsolete "+/*,rlibbarcode ,rlibln*/

    ",rlibrdicid)" +

    "values ('" + rLibrary + "','" + rItem + "','" + rItemCategory + "','" +

    rItemDescription + "','" + rItemObsolete + "','" /*+ rItemBarCode + "','"+ rItemBarCode + "','"*/

    + rLibDicID + "')";

    #endregion

    try

    {

    rConnection.Open();

    rQrySqlCmd.Connection = rConnection;

    rQrySqlCmd.CommandText = kQuery;

    rQrySqlCmd.ExecuteNonQuery();

    //Explodes here (_COMPlusExceptionCode = -532459699,e = {"Conversion failed when converting from a character string to uniqueidentifier."}

    }

    catch (Exception e)

    {

    MessageBox.Show(e.ToString());

    }

    finally

    {

    rConnection.Close();

    }

    i apologize for my written

    thanks

     

    Thursday, November 22, 2007 4:29 PM

Answers

  • Hi

     

    If you want to pass NULL as a GUID value, you have several options:

    1. do not specify its name and value inside INSERT command - it will have default value NULL
    2. use NULL string, but do not enclose it with single quotes. I see in your code that you enclose every value with single quotes - you need to change it and add special support for NULL values that are not enclosed. The command will be like:
      INSERT INTO [MyTable] ([Name], [ID]) VALUES ('Name1', NULL)

    If your database does not support NULL values for GUID, you can use empty GUID value, which is Guid.Empty.ToString(). If the ID field must always have a valid GUID, you can use Guid.NewGuid().ToString() value to create new uniqie guid. In both cases, if you do provide a GUID value (either empty or unique or other), you should enclose it with single quotes.

     

    Let me know if you have more questions,

     Nissim

     

    Monday, November 26, 2007 8:50 PM
    Moderator

All replies

  • Hi

     

    If you want to pass NULL as a GUID value, you have several options:

    1. do not specify its name and value inside INSERT command - it will have default value NULL
    2. use NULL string, but do not enclose it with single quotes. I see in your code that you enclose every value with single quotes - you need to change it and add special support for NULL values that are not enclosed. The command will be like:
      INSERT INTO [MyTable] ([Name], [ID]) VALUES ('Name1', NULL)

    If your database does not support NULL values for GUID, you can use empty GUID value, which is Guid.Empty.ToString(). If the ID field must always have a valid GUID, you can use Guid.NewGuid().ToString() value to create new uniqie guid. In both cases, if you do provide a GUID value (either empty or unique or other), you should enclose it with single quotes.

     

    Let me know if you have more questions,

     Nissim

     

    Monday, November 26, 2007 8:50 PM
    Moderator
  • Thanks Nissim, I've solved the problem

    Wednesday, November 28, 2007 8:20 AM