I have a List of News and in here i tried to save/update to the database.News List comes as a LIST and here i have foreach the news list and trying to do the operation.But the issue is Always 1 item goes to Inserted section and save it to the database and all other items it doesn't exists in the database as goes to Update Query section
MyCode
public string SaveNewsDetails(List<TempNews> listTempNews, int RowCount)
{
int value;
string NewsStatus = string.Empty;
StringBuilder sqlBuilder = new StringBuilder();
DataAccess db = DataAccess.Create("Conn");
try
{
using (var trn = db.BeginTransaction())
{
foreach (var item in listTempNews)
{
IEnumerable<string> newsList = null;
sqlBuilder.Append("SELECT NewsCode ");
sqlBuilder.Append("FROM T_NEWS ");
sqlBuilder.Append("WHERE NewsCode = '" + item.N_Code + "'");
newsList = trn.Query<string>(sqlBuilder.ToString());
if (newsList == null || newsList.Count() == 0)
{
// Insert to table Query goes here
}
else
{
// Update Query Goes here
}
trn.Execute(sqlBuilder.ToString());
}
trn.Complete();
}
}
catch (Exception Ex)
{
}
return NewsStatus;
}