How to solve: A syntax error occurs when the string is converted to uniqueidentifier.

Source: Internet
Author: User
The following error occurs during project Compilation:

A syntax error occurs when you convert a string to uniqueidentifier.
Note: An unhandled exception occurs during the execution of the current Web request. Check the stack trace information to learn about this error andCodeDetailed information about the cause of the error.

Exception details: system. Data. sqlclient. sqlexception: A syntax error occurs when the string is converted to uniqueidentifier.

Source error:

Line 110: fdataset = new dataset ();
Line 111: If (init_ SQL .length> 0)
Line 112: fdataadapter. Fill (fdataset );
Row 113:
Row 114 :}

The reason is as follows:

the parameter type is inconsistent with the database field type. The database field type is uniqueidentifier, in the Program , the parameter type is string and needs to be converted. Conversion Method: string guid = system. guid. newguid (). tostring (); // or system. guid. empty. tostring ();

system. guid G = New GUID (guid); // convert a database field to a guid type when assigning a value

or do not define it as a string type. It is directly defined as a guid type, for example,
set
Public static readonly string zerouniqueid = "{00000000-0000-0000-0000-000000000000 }"; // indicates a nonexistent ID.
changed to
Public static readonly guid zerouniqueid = system. guid. empty; // indicates a non-existent number.
in this way, you can assign values to database fields without any conversion.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.