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 ??
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 ??