0
In one of the system tasks, I need to query an Sql Server database, which returns a Datatable
, in this Datatable
, one of the data is of the type Byte[]
So to read the Datatable
use a DataTableReader
, that generates me a Object
, right?
async private void Upload_Ra(DataTable Dat_RaWebLocal)
{
DataTableReader dtr = Dat_RaWebLocal.CreateDataReader();
if(dtr.HasRows)
{
textBox2.Text = "Relatorio encontrado, iniciando enviado para nuvem";
Classes.Cadastro.Crm.Upload_RaWeb Up_RaWeb = new Classes.Cadastro.Crm.Upload_RaWeb();
await dtr.ReadAsync();
Up_RaWeb.Upload(Convert.ToInt32(dtr["id"]), dtr["cod_item_Crm"].ToString(), Convert.ToInt32(dtr["cod_cli"]), dtr["razao_social"].ToString(), Convert.ToDateTime(dtr["data_rec"])
, Convert.ToDateTime(dtr["data_anal"]), Convert.ToInt32(dtr["n_Crm"]), Convert.ToInt32(dtr["n_Nf"])
, dtr["OF_anterior"].ToString(), dtr["modelo"].ToString(), dtr["material"].ToString(), dtr["arranjo"].ToString(), dtr["diam"].ToString()
, dtr["tipo"].ToString(), dtr["inicio_op"].ToString()
, dtr["fim_op"].ToString(), dtr["motivo"].ToString(), dtr["tag"].ToString(), dtr["fabric_bomba"].ToString(), dtr["mod_bomba"].ToString()
, dtr["prod_fluido"].ToString(), Convert.ToDecimal(dtr["temp_fluido"])
, Convert.ToDecimal(dtr["rpm"]), dtr["api"].ToString(), Convert.ToDecimal(dtr["pres_suc"]), Convert.ToDecimal(dtr["pres_desc"])
, dtr["diag_falha"].ToString(), dtr["analise"].ToString(), dtr["conclusao"].ToString()
, dtr["recomend"].ToString(), Convert.ToInt32(dtr["nivel"]), ObjectToByteArray(dtr["bfoto1"]), "", ObjectToByteArray(dtr["bfoto2"]), ""
, ObjectToByteArray(dtr["bfoto3"]), "", ObjectToByteArray(dtr["bfoto4"]), "", ObjectToByteArray(dtr["bfoto5"]), "", ObjectToByteArray(dtr["bfoto6"]), "");
}
}
So I need to convert this Object
for Byte[]
so you can save to another server.
So, researching, I found the following question:
Convert any Object to a byte[]
Then, using the method below:
byte[] ObjectToByteArray(object obj)
{
if(obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
I was able to convert the Object
for byte[]
, but, I noticed that the same totally changed the string, this certain?
There’s another way I can get that array
?
The
dtr["bfoto3"]
its value is not aarray de bytes
if yes no need to convert again toarray de bytes
just give onecast
in that variable!– novic
@Virgilionovic Perfect. Thank you
– Thomas Erich Pimentel