private int _saveRecord()
{
string _tableName = DBStructure.TABLE_SITE_POWER_PLANT_MASTER;
int _retVal = -1;
int _errorCode = (int)ErrorCodes.NoError;
try
{
if (PowerPlantTable.Rows.Count > 0)
{
foreach (DataRow _dr in PowerPlantTable.Rows)
{
RecordValues[] _newRec = new RecordValues[6];
_newRec[0].FieldName = DBStructure.SITE_POWER_PLANT_MASTER_POWER_PLANT_ID;
_newRec[0].FieldType = Fieldtypes.Integer;
_newRec[0].FieldValue = _dr["Power Plant"].ToString();
_newRec[1].FieldName = DBStructure.SITE_POWER_PLANT_MASTER_METER_SLAVE_ID;
_newRec[1].FieldType = Fieldtypes.Integer;
_newRec[1].FieldValue = _dr["DC Meter"].ToString();
_newRec[2].FieldName = DBStructure.SITE_POWER_PLANT_MASTER_CHANNEL_ID;
_newRec[2].FieldType = Fieldtypes.Integer;
_newRec[2].FieldValue = _dr["Channel ID"].ToString();
_newRec[3].FieldName = DBStructure.SITE_POWER_PLANT_MASTER_CREATED_BY;
_newRec[3].FieldType = Fieldtypes.VarChar;
_newRec[3].FieldValue = UserName.ToString();
_newRec[4].FieldName = DBStructure.SITE_POWER_PLANT_MASTER_CREATED_DATE;
_newRec[4].FieldType = Fieldtypes.Int;
_newRec[4].FieldValue = UpdatedTime.ToString();
_newRec[5].FieldName = DBStructure.SITE_POWER_PLANT_MASTER_SITE_ID;
_newRec[5].FieldType = Fieldtypes.Integer;
_newRec[5].FieldValue = SiteID.ToString();
if (_dr["SiteID"].ToString().Equals("0"))
{
_retVal = _dalAccess.Insert(false, _tableName, _newRec, out _errorCode);
if (_errorCode == (int)ErrorCodes.NoError)
{
StatusDescription = GetGlobalResourceObject(globalResourceFileName, "InsertedSucessfully").ToString();
}
else
StatusDescription = _errorLogger.GetErrorMessage(_errorCode);
}
else
{
cndCheck[] _whClause = new cndCheck[1];
_whClause[0].FieldName = DBStructure.SITE_POWER_PLANT_MASTER_SITE_ID;
_whClause[0].FieldType = Fieldtypes.Integer;
_whClause[0].FirstFieldValue = _dr["SiteID"].ToString();
_whClause[0].ArithmeticOp = ArithmeticOperator.EQUALS;
_retVal = _dalAccess.Update(false, _tableName, _newRec, _whClause, out _errorCode);
if (_errorCode == (int)ErrorCodes.NoError)
{
StatusDescription = GetGlobalResourceObject(globalResourceFileName, "UpdatedSuccessfully").ToString();
}
else
StatusDescription = _errorLogger.GetErrorMessage(_errorCode);
}
}
}
else
{
StatusDescription = GetGlobalResourceObject(ResorceFileName, "PowerPlantNotExists").ToString();
}
return _retVal;
}
catch (Exception ex)
{
_errorLogger.PrintUnknownError(ex.Message.ToString(), GetModuleName(), _getPageName(), "_saveRecord()");
return -1;
}
}
private void _updateToDataTable(int _rowIndex)
{
try
{
bool blCheck = _checkEditData(_rowIndex);
if (blCheck)
{
PowerPlantTable.Rows[_rowIndex].BeginEdit();
DataRow dr = PowerPlantTable.Rows[_rowIndex];
dr["Power Plant"] = cmbPowerPlant.SelectedItem.Text;
dr["DC Meter"] = cmbDcMeter.SelectedItem.Text;
dr["Channel ID"] = cmbChannel.SelectedItem.Text;
ViewState.Remove("rowIndex");
PowerPlantTable.AcceptChanges();
wbtnSave.Text = GetGlobalResourceObject(globalResourceFileName, "lnkAdd").ToString();
wbtnSave.ToolTip = GetGlobalResourceObject(globalResourceFileName, "lnkAddToolTip").ToString();
_setPageAccessibilty();
_clearControls();
}
else
{
StatusDescription = GetGlobalResourceObject(ResorceFileName, "PPExists").ToString();
}
}
catch (Exception Ex)
{
_errorLogger.PrintUnknownError(Ex.Message, GetModuleName(), _getPageName(), "_updateToDataTable()");
}
}
wen i add records and come out of the list page n again go back and edit the saved record
after saving the record will be discarded from the grid and records are saving multiple times in database overriding the existing records
where am i going wrong?
please someone help me wid this piece of code