If conversion to binary fails for some reason you could try to use the sql server type uniqueidentifier. Maybe you're more lucky then.
Since we speak about MySQL this might not be an option afterall.
Instead on the .NET part you should make sure the GUID is converted accordingly.
For .NET Guid-type values generated via Guid.NewGuid() you can pass them to a MySqlCommand Parameter if you cast the guid value as Byte Array.
This can be done via Guid.ToByteArray() as mentioned below:
string connectionString = string.Format("Server={0};Database={1};Uid={2};pwd={3}", "server", "database", "user", "password");
Guid orgId = Guid.NewGuid();
Guid fromDb = Guid.Empty;
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
conn.Open();
using (MySqlCommand cmd = new MySqlCommand("INSERT INTO test (id) VALUES (?id)", conn))
{
cmd.Parameters.Add("id", MySqlDbType.Binary).Value = orgId.ToByteArray();
cmd.ExecuteNonQuery();
}
using (MySqlCommand cmd = new MySqlCommand("SELECT id FROM test", conn))
{
using (MySqlDataReader r = cmd.ExecuteReader())
{
r.Read();
fromDb = new Guid((byte[])r.GetValue(0));
}
}
}