Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C# WindowsForm
I have to memorize a simple text present in a TextBox
e.g: 
line1
line2
line3

into a BlobFiels MySql (medium Blob)
...

and then read and assign to TextBox


What I have tried:

byte[] byteBLOBData = (Byte[])(row["FIELDNAME"]);
String s = System.Text.Encoding.UTF8.GetString(byteBLOBData);


(Byte[])(row["FIELDNAME"])

row .... not recognized

what it is row ... object, variable ?
Posted
Updated 15-Dec-19 0:43am
Comments
Richard MacCutchan 9-Dec-19 10:18am    
What is row?
Ashutosh Gpta 9-Dec-19 10:43am    
@Member 13174280, you have tried the solution then definlty you would have define the type of row, right, but anyways my impression seems to be you are using grid and row is type of DataRow and FIELDNAME is column name.

We can't tell: it needs the rest of that method to give context to the error message.
But ... at a guess, you are using a DataReader or a DataTable in a loop to access the data, and row should be related to that loop.

So look at the code around that line, and see what changes automatically each time round the loop - that is probably what you should be using instead of row
 
Share this answer
 
Comments
Member 13174280 9-Dec-19 12:32pm    
ok, thanks; my error on row
this is correct.

DataTable dtFoto = new DataTable();
dtFoto = gesdb.QryRead(conn, dtFoto, Query); //execute query

MemoryStream ms;

int x = 0;
foreach (DataRow row in dtFoto.Rows)
{
FileImg = row["description"].ToString();

byte[] byteBLOBData = (Byte[])(row["public_note"]);
textBox1.Text = Encoding.UTF8.GetString(byteBLOBData);
}

then Blob is
line1
line2
...
the result is line1/nline2/nline3/n
texBox1 does not apply the /n
and show line1line2line3
OriginalGriff 9-Dec-19 12:51pm    
Well of course it won't!
If you did this:
int x = 1;
x = 2;
x = 3;
Console.WriteLine(x);
Would you expect it to write "3" or "6"?
You are doing the same thing with your TextBox - each time round the loop you set the value to the current string and discards all previous ones.

To assemble each on a separate line of a multiline Textbox, you need to either assemble all lines into an array of strings and set the Lines property, or add each line of text with a Environment.Newline separating them.
Member 13174280 9-Dec-19 13:44pm    
this routine solve then \n

string newLine = Environment.NewLine;
int at = 0;
string app;
string app1 = "";

while (s.Length > 0)
{
at = s.IndexOf("\n");
app = s.Substring(0, at) + newLine;
s = s.Substring(at + 1);
app1 = app1 + app;
}

textBox1.Text = app1;

now show
line1
line2
...
linex
Patrice T 14-Dec-19 19:56pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900