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 3489244
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:22:20+00:00 2026-05-18T11:22:20+00:00

MySQL 5.0 Connector.NET Examples states: GetBytes returns the number of available bytes in the

  • 0

MySQL 5.0 Connector.NET Examples states:

GetBytes returns the number of available bytes in the field. In most cases this is the exact length of the field.

However, MySQL 5.0 Connector.NET Documentation lists the return value of GetBytes as the number of bytes read into the buffer.

To me this isn’t the same thing at all!

Regardless, my question is: what’s the most readable construction to get the content from the datasource into a MemoryStream object? I’m using the return value from GetBytes to increment the data index parameter of the GetBytes method but seemingly I keep overrunning the field because I get IndexOutOfRangeException being thrown.

  • 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-05-18T11:22:20+00:00Added an answer on May 18, 2026 at 11:22 am

    I agree that the documentation for MySqlDataReader leaves a lot to be desired.

    When you pass null as the buffer argument, GetBytes returns the total length of the field. When you pass a non-null buffer argument, GetBytes returns the number of bytes that were written into the buffer.

    long length = yourReader.GetBytes(columnOrdinal, 0, null, 0, 0);
    long offset = 0;
    var buffer = new byte[4 * 1024];    // 4KB buffer
    var ms = new MemoryStream();
    
    while (length > 0)
    {
        long bytesRead = yourReader.GetBytes(columnOrdinal, offset, buffer, 0,
                                             (int)Math.Min(length, buffer.Length));
    
        if (bytesRead > 0)
        {
            ms.Write(buffer, 0, (int)bytesRead);
            length -= bytesRead;
            offset += bytesRead;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've found this at connection strings.com http://connectionstrings.com/mysql Do I need to download connector-net from
I'm a beginner at this. I'm using mysql connector .net to connect vb.net with
According to MySql in this document C.7.9.6. Changes in MySQL Connector/NET 5.0.5 (07 March
I have the MySQL Connector/NET installed on my PC. I modified the source code
I'm using MySql Connector .NET to load an account and transfer it to the
I have downloaded MySQL Connector .NET 6.4.2 and installed it on my system for
I'm using a MySQL connector in VB .Net to execute a batch of SQL
I have a C# .NET 3.5 application using the ADO.NET Driver for MySQL (Connector/NET).
I downloaded MySql Connector/NET, and set it as a reference in my project. I
I am using MySQL Connector/.NET and a custom MySQL membership provider. Here is a

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.