public Int32 SQL_GetMaxValue(string TableName, string FieldName)
{
return SQL_GetMaxValue(TableName, FieldName, "");
}
public Int32 SQL_GetMaxValue(string TableName, string FieldName, string WhereCondition)
{
try
{
string SQLString = "SELECT MAX(" + FieldName + ") FROM " + TableName;
if (WhereCondition != "") { SQLString += " WHERE " + WhereCondition; }
objCN.Close();
objCN.Open();
SqlCommand objCMD = new SqlCommand(SQLString, objCN);
Int32 MaxValue = Convert.ToInt32(objCMD.ExecuteScalar());
objCN.Close();
return MaxValue;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
Object cannot be cast from DBNull to other types.
this error i m getting