Please i want to COnvert DataTable thta has Blob as part of its fields to CSV.
so i can do MySqlBulkCopy to MySql Database.
I have sucessfully copy all columns except the image data.
I need help please.
Thak you.
What I have tried:
I have successfully bulkcopy all columns except the blob coumn it copies it and inserts "System.Byte[]" in the database
This is the code to insert to Database
IGRDal dl = SQLDalFactory.GetDal(GrConnector.AccessSQLDal);
string tempCsvFileSpec = APP_PATH+ @"\dump.csv";
using (StreamWriter writer = new StreamWriter(tempCsvFileSpec))
{
DBHelper.WriteDataTable(dl.CreateDataTable(), writer, false);
}
dbConection.Open();
var msbl = new MySqlBulkLoader(dbConection);
msbl.TableName = "tb_templates";
msbl.FileName = tempCsvFileSpec;
msbl.FieldTerminator = ",";
msbl.FieldQuotationCharacter = '"';
msbl.Load();
File.Delete(tempCsvFileSpec);
this is the code to make CSV
public static void WriteDataTable(DataTable sourceTable, TextWriter writer, bool includeHeaders)
{
if (includeHeaders)
{
IEnumerable<string> headerValues = sourceTable.Columns
.OfType<datacolumn>()
.Select(column => QuoteValue(column.ColumnName));
writer.WriteLine(String.Join(",", headerValues));
}
IEnumerable<string> items = null;
foreach (DataRow row in sourceTable.Rows)
{
items = row.ItemArray.Select(o => QuoteValue(o.ToString()));
writer.WriteLine(String.Join(",", items));
}
writer.Flush();
}
private static string QuoteValue(string value)
{
return String.Concat("\"",
value.Replace("\"", "\"\""), "\"");
}</string></datacolumn></string>