I need to pass data from UI throw code behind using Entity and BAL, DAL and DBHelper layers.
I store the path as list of data and send it from code behind To BAL to DAL The Code I have inn DAL is
public static bool InsertFile(List<GSFile> files)
{
try
{
using (DBHelper helper = new DBHelper())
{
foreach (var obj in files)
{
GSFile query = new GSFile();
query.Name = obj.Name;
query.Hash = obj.Hash;
query.Path = obj.Path;
helper.AddParameter("@parmName", obj.Name);
helper.AddParameter("@parmPath", obj.Path);
helper.AddParameter("@parmHash", obj.Hash);
helper.SetStoredProcedureName("SP_Files_Insert");
return helper.ExecuteNonQuerys(query);
}
//return clearquery;
}
}
catch (Exception ex)
{
throw ex;
}
}
The Code in DBHelper is:
public bool ExecuteNonQuerys(GSFile files)
{
try
{
foreach (var item in files)
{
mySqlCommand.Parameters[item.key].Value = item.value;
}
return true;
}
catch (Exception ex)
{
throw ex;
}
}
I need help to make this code work. I mean how to use this statement ...
mySqlCommand.Parameters[item.key].Value = item.value;
... to change the parameter value?
When send list of objects then it should make foreach loop for each item in the object.
foreach (var file in files)
{
foreach(var item in file)
{
mySqlCommand.Parameters[item.key].Value = item.value;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.