Re: .NET & fields of type text
Posted by: Davy Radiuju
Date: June 29, 2005 02:29PM

Hi,

After days of work, I finally found out a way to display those text fields in a satisfying way, instead of getting "System.Bytes[]".

Here is what I did (C# code) :

MySQLConnection DBConn = new MySQLConnection(new MySQLConnectionString("xx.xx.xx.xx.xx", "mydb", "xxxx", "xxxx").AsString);

DBConn.Open();

// Write your query here
string sql = "SELECT * FROM mytable";

MySQLCommand cmd = new MySQLCommand(sql,DBConn);

MySQLDataReader reader = cmd.ExecuteReaderEx();

while(reader.Read())
{

// First, you have to create a table of bytes (size = 1000 in this example)
byte[] comment_byte = new byte[1000];

// Use the GetBytes method (in this example, I used the third field of my table, which is a "text" field, and third field means index = 2)
long comment_lenght = reader.GetBytes(2,0,comment_byte, 0, 1000);

//check the lenght of the field
Console.WriteLine(comment_lenght);

// convert bytes to char
char[] comment_char = new Char[1000];

int i = 0;

for (i=0;i<1000;i++)
{
comment_char = System.Convert.ToChar(comment_byte);
}

// convert char to string
string[] comment_string = new String[1000];

for (i=0;i<1000;i++)
{
comment_string = System.Convert.ToString(comment_char);
}

// Concatenate strings
string comment_txt = "";

for (i=0;i<1000;i++)
{
comment_txt = comment_txt + comment_string;
}

//For example display the result in a richTextBox, and you are done !
richTextBox1.Text = comment_txt;

}

reader.Close();

DBConn.Close();

I guess the MySQLDriverCS developpers simply forgot to deal with "text" fields.

I hope this will be helpful.

Best regards from France,

Davy

Options: ReplyQuote


Subject
Written By
Posted
February 02, 2005 08:56AM
February 02, 2005 10:10AM
March 26, 2005 06:28PM
Re: .NET & fields of type text
June 29, 2005 02:29PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.