Answer the question
In order to leave comments, you need to log in
Why is Stream needed in C#?
It took me here in C # to write a tiny application. The task is to read a blob from one database and write it to another (also a blob).
C# I know only superficially. I don't understand this moment. Why are some Streams used in all the examples?
byte[] userBlob;
myCommand.CommandText = "SELECT id, userblob FROM USERS";
myCommand.Connection = myFBConnection;
myCommand.Transaction = myTransaction;
FbDataReader reader = myCommand.ExecuteReader();
try
{
while(reader.Read())
{
Console.WriteLine(reader.GetString(0));
userBlob = // Вот тут что должно быть? Читать как биты или поток
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Can't read data from DB");
}
userBlob = reader.GetBytes(0,0,userBlob,0,userBlob.Length);
Answer the question
In order to leave comments, you need to log in
GetBytes returns a long, I don't know where you found that it returns an array of bytes:
https://msdn.microsoft.com/en-us/library/system.da...
So passing a buffer as the third parameter is more than logical.
Come on?) Didn't that make you think about the type of return value?) Did you come up with it yourself that it returns an array of bytes?
Well, if you still go through the documentation, then below you will see the following:
GetBytes returns the number of bytes available in the field. This value is often equal to the exact length of the field. However, the number returned may be less than the actual length of the field if GetBytes has already been used to get bytes from the field.
When passing a buffer whose value is null, the GetBytes method returns the length of the string in bytes.
Apparently you are using Firebird. I can't figure out which library is being used.
Have you looked here? codeproject I can assume that you need to get data like this userBlob = reader[column number];
But I advise you to better read the documentation for the specific library that you are using, or use another library for your database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question