×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Bytea reading problem!!

Bytea reading problem!!

Bytea reading problem!!

(OP)
Hi,
I am developing an application on c# .net2005 using postgres.
 I have created a table named "data" it has 8 fields and all field types are bytea, because i am receiving byte arrays from TCP/IP socket, after i parsed them,i am insertnig byte arrays to my table "data"..
the values i received and inserted are ;
To 1. Field :00 // 1 byte
To 2. Field :04 // 1 byte
To 3. Field :A3 // 1 byte
To 4. Field :00 // 1 byte
.....
.....
.....

So far so good,

But when i tried to read data from table using;


public void ReadDataFromDatabase()
{
string ConnectionString = "Server=localhost;Port=5432;User Id=Ikado;Password=muhammet;Database=" + DatabaseName + ";";
            NpgsqlConnection conn = new NpgsqlConnection(ConnectionString);
            conn.Open();
            IDbCommand cmd = null;
            IDataReader reader = null;
            try
            {
             cmd = conn.CreateCommand();
             cmd.CommandType = CommandType.Text;
             cmd.CommandText = SQL;// SQL= "SELECT * FROM data"
             cmd.Connection = conn;
                reader = cmd.ExecuteReader();
                reader.Read();
                //it allows me at least 3 byte
                //otherwise i am getting an error message
                //telling there is no t enough space at PoolData
                //array
                byte[] PoolData = new byte[3];
//BytetoHex Function converts given byte array to
// hexadecimal string
                while (reader.Read())
                {
                reader.GetBytes(1, 0, PoolData, 0, 1);
                MessageBox.Show(ByteToHex(PoolData));
                // Result : 30 30 20
                reader.GetBytes(2, 0, PoolData, 0, 1);
                MessageBox.Show(ByteToHex(PoolData));
                // Result : 30 34 20
                reader.GetBytes(3, 0, PoolData, 0, 1);
                MessageBox.Show(ByteToHex(PoolData));
                // Result : 41 33 20
                reader.GetBytes(4, 0, PoolData, 0, 1);
                MessageBox.Show(ByteToHex(PoolData));
                // Result : 30 30 20
                }
            }             
}

I am inserting only one byte but when i tried to read i am receiving 3 bytes per field, what is wrong?
Can you help me ??

RE: Bytea reading problem!!

Is this a postgresql-question?

Does it work with another database as expected?
Can you reproduce the error in plain sql?


CODE

hex..........dez..........ascii
30 30 20 ... 48 48 32 ... "00 "
30 34 20 ... 48 52 32 ... "04 "
41 33 20 ... 65 51 32 ... "A3 "
30 30 20 ... 48 48 32 ... "00 "

My documentation says (datatype-binary.html):
bytea    4 bytes plus the actual binary string    variable-length binary string
So maybe you're inserting allways 3 bytes when you think it's just one.

don't visit my homepage: http://home.arcor.de/hirnstrom/bewerbung

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close