i trying read binary database , write file in local disk using c#.
using below code... there problem in line : byte[] fileasbyte = byte.parse(row["blob"]);
public static void readblob() { int icount = 0; string filename; sqlconnection mycon = new sqlconnection(con); mycon.open(); string querystring = "select * " + tblname; sqldataadapter adapter = new sqldataadapter(querystring, mycon); datatable dtblob = new datatable(); adapter.fill(dtblob); foreach (datarow row in dtblob.rows) { byte[] fileasbyte = byte.parse(row["blob"]); filename = filepath + tblname + row["blobid"].tostring() + filetype; writeblob(fileasbyte, filename); } mycon.close(); } public static void writeblob(byte[] buff, string filename) { try { filestream fs = new filestream(filename, filemode.create, fileaccess.readwrite); binarywriter bw = new binarywriter(fs); bw.write(buff); bw.close(); } catch (exception ex) { console.writeline(ex.message); } }
byte.parse
try parse single byte. have tried casting?
byte[] fileasbyte = (byte[]) row["blob"];
if fails, should @ least show type actually in datarow
. it's type reasonably convertible byte[]
.
Comments
Post a Comment