2

I know how to insert String:

MySqlConnection connection = new MySqlConnection();
connection .Open();
MySqlCommand command = connection.CreateCommand();
command.CommandText = "INSERT INTO User ('username') VALUE ('David')");
command.ExecuteNonQuery();
connection.Close();

How can I insert binary data using varBinary?

1
  • 1
    remove quotes (') from field name. Commented Mar 3, 2012 at 16:17

1 Answer 1

1

You can insert string as is -

command.CommandText = "INSERT INTO User (username) VALUE ('David')");

Also, you can insert data as a hex value, use Encoding.GetBytes method to get array of butes, then convert bytes to a hex string (write special function), the result should be like this -

command.CommandText = "INSERT INTO User (username) VALUE (0x4461766964)");
Sign up to request clarification or add additional context in comments.

2 Comments

What would I do if got 2K of data to insert, this string can be extremely long...
2K is not too long. It is important that the size of the packet was not greater than the value of max_allowed_packet - dev.mysql.com/doc/refman/5.5/en/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.