public static class convertt
{
public static DataTable ToDataTable<TSource>(this IList<TSource> data)
{
DataTable dataTable = new DataTable(typeof(TSource).Name);
PropertyInfo[] props = typeof(TSource).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in props)
{
dataTable.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
}
foreach (TSource item in data)
{
var values = new object[props.Length];
for (int i = 0; i < props.Length; i++)
{
values[i] = props[i].GetValue(item, null);
}
dataTable.Rows.Add(values);
}
return dataTable;
}
}
then call here
public void SaveRoleMaintenance(List<BOAdmin> lstBOAdmin)
{
try
{
BLDataHelper oBLDataHelper = new BLDataHelper();
oBLDataHelper.CreateDBObjects(BLDataHelper.Providers.SqlServer, BLDataHelper.Database.PSASMVC);
DataTable dtrolemaintenance =convertt.ToDataTable<BOAdmin>(lstBOAdmin);
SqlParameter sprolemaintenance = new SqlParameter("roledt", dtrolemaintenance);
sprolemaintenance.SqlDbType = SqlDbType.Structured;
oBLDataHelper.AddParameter("@roledt", dtrolemaintenance);
oBLDataHelper.AddParameter("@mark", 1);
object response = oBLDataHelper.ExecuteNonQuery("sp_RoleMaintenance", System.Data.CommandType.StoredProcedure);
}
catch
{
throw;
}
}
{
public static DataTable ToDataTable<TSource>(this IList<TSource> data)
{
DataTable dataTable = new DataTable(typeof(TSource).Name);
PropertyInfo[] props = typeof(TSource).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in props)
{
dataTable.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
}
foreach (TSource item in data)
{
var values = new object[props.Length];
for (int i = 0; i < props.Length; i++)
{
values[i] = props[i].GetValue(item, null);
}
dataTable.Rows.Add(values);
}
return dataTable;
}
}
then call here
public void SaveRoleMaintenance(List<BOAdmin> lstBOAdmin)
{
try
{
BLDataHelper oBLDataHelper = new BLDataHelper();
oBLDataHelper.CreateDBObjects(BLDataHelper.Providers.SqlServer, BLDataHelper.Database.PSASMVC);
DataTable dtrolemaintenance =convertt.ToDataTable<BOAdmin>(lstBOAdmin);
SqlParameter sprolemaintenance = new SqlParameter("roledt", dtrolemaintenance);
sprolemaintenance.SqlDbType = SqlDbType.Structured;
oBLDataHelper.AddParameter("@roledt", dtrolemaintenance);
oBLDataHelper.AddParameter("@mark", 1);
object response = oBLDataHelper.ExecuteNonQuery("sp_RoleMaintenance", System.Data.CommandType.StoredProcedure);
}
catch
{
throw;
}
}
No comments:
Post a Comment