Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:32:06+00:00 2026-06-13T07:32:06+00:00

Possible Duplicate: How should I store GUID in MySQL tables? VARCHAR will return as

  • 0

Possible Duplicate:
How should I store GUID in MySQL tables?

VARCHAR will return as string
BLOB will return as byte[]
but, what column type of MySQL will return as System.Guid in C#
thanks.

Edited: I have found the answer

thanks to DaveHogan that gives me the clue about ORM (Object Relation Mapping)
I started to look for information about the datatype conversion(mapping) made by Connector/NET.
I’m using MySQL Dot Net Connector (Connector/NET)
there are different 3 situations that Connector/NET performs.

Below are what I have found:

1st Situation:
Start from Connnector/NET 6.1.1, CHAR(36) will be automatically converted as System.GUID in C# and BINARY(16) will be treated as System.Byte[].

2nd Situation:
If you use older Connector/NET, BINARY(16) will be automatically converted as System.GUID when the value is passed into C# and CHAR(36) will be treated as System.String.

3rd Situation:
If you use newer Connector/NET (newer than 6.1.1), and if you want to use BINARY(16) AS System.GUID (be default it is not), you have to add a connection option Old Guids=true in the Connection String.
Example:

server=localhost;user=root;password=qwerty;database=test;old guids=true;

by this, CHAR(36) will be converted as System.String and BINARY(16) = System.GUID

Read more about connection options of Old Guids at:
MySQL 5.6 Reference Manual: 21.2.6. Connector/Net Connection String Options Reference

———————————————————————-
Extra Info:
How to Insert System.GUID into MySql Database
———————————————————————-
This is a sample table, that we are going to insert the System.GUID:

CREATE TABLE `testdata` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `binary` binary(16) DEFAULT NULL,
  `char` char(36) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

Insert System.GUID into MySQL

string constr = "server=localhost;user=root;pwd=qwerty;database=test;";
using (MySqlConnection conn = new MySqlConnection(constr))
{
    conn.Open();

    // Create a System.GUID
    byte[] ba = new byte[16];
    Random rd = new Random();
    rd.NextBytes(ba);
    System.Guid guid = new Guid(ba);

    // Prepare GUID values in SQL format
    string guidForChar36 = guid.ToString();
    string hexstring = BitConverter.ToString(guid.ToByteArray());
    string guidForBinary16 = "0x" + hexstring.Replace("-", string.Empty);

    string sql = "insert into testdata(`binary`,`char`)"
               + "values(" + guidForBinary16 + ","
               + "'" + guidForChar36 + "');";

    MySqlCommand cmd = new MySqlCommand(sql, conn);
    cmd.ExecuteNonQuery();

    conn.Close();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:32:07+00:00Added an answer on June 13, 2026 at 7:32 am

    EDIT:

    Sorry I misunderstood your question. You should use

    BINARY(16)
    

    How you cast that to a System.Guid depends on whether you’re using an ORM etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How should I store GUID in MySQL tables? Hello, To represent a
Possible Duplicate: How should be kept as HTML tags in database? I will store
Possible Duplicate: What type should I store IP addresses for MySQL? One single datatype
Possible Duplicate: Android: I lost my android key store, what should I do? I
Possible Duplicate: How should I store UIImages within my Core Data database? I decided
Possible Duplicate: How or where should I store object instances that I require globally
Possible Duplicate: Should I store DateTimes as a Long (Ticks) in a database? It
Possible Duplicate: Should I use != or <> for not equal in TSQL? Behavior
Possible Duplicate: Should Usings be inside or outside the namespace sa1200 All using directives
Possible Duplicate: Should C++ eliminate header files? In languages like C# and Java there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.