I have been trying to get a blob data from database through a stored procedure I am able to get the data but the problem is the data is for an ASP.NET MVC application where it converts using ConvertToList
:
public static List<T> ConvertToList<T>(this DataTable dt)
{
var columnNames = dt.Columns.Cast<DataColumn>().Select(c => c.ColumnName).ToList();
var properties = typeof(T).GetProperties();
return dt.AsEnumerable().Select(row =>
{
var objT = Activator.CreateInstance<T>();
foreach (var pro in properties)
{
if (columnNames.Contains(pro.Name))
{
if (pro.PropertyType == Type.GetType("System.Int32"))
pro.SetValue(objT, row[pro.Name].ToString().ToInt32(), null);
else if (pro.PropertyType == Type.GetType("System.Double"))
pro.SetValue(objT, row[pro.Name].ToString().ToDouble(), null);
else if (pro.PropertyType == Type.GetType("System.String"))
pro.SetValue(objT, row[pro.Name].ToString(), null);
else if (pro.PropertyType == Type.GetType("System.Int64"))
pro.SetValue(objT, row[pro.Name].ToString().ToInt32(), null);
else if (pro.PropertyType == Type.GetType("System.Boolean"))
pro.SetValue(objT, Convert.ToBoolean(row[pro.Name].ToString()), null);
//else if (pro.PropertyType == Type.GetType("System.Byte[]"))
// pro.SetValue(objT, Convert.ToByte(row[pro.Name]), null);
}
}
return objT;
}).ToList();
}
When a System.Byte[]
data is fetched, it always is set to null; I have tried to convert it using usual Byte to string conversion such as
string result = System.Text.Encoding.UTF8.GetString(byteArray);
and
string s3 = Convert.ToBase64String(bytes);
This cannot be done since my return
type is a var
so I tried to convert using stored procedure while it's selecting like this
CONVERT(VARCHAR(MAX), LME.CoverPageImage, 2)
but it's still returning null value after the ConvertToList
is called!
Is there any way to get it as a string from the database through a stored procedure or to convert it using C# ASP.NET MVC?