I miss this requriement for the value function today, How would i use the datatable and datarow in the function below. I am simply setting the int vlue
void SetValue(this DataTable datatable, DataRow datarow, string columnName, int value)
{
}
{
}

Joginder BangerRank #360 · 7K reputationPosted Dec 15, 2014, 9:46 PM EST
i can't understand what's you try. plz explore the problem what's you try or share more code for better understand.
VulpesRank #55 · 29.2K reputationPosted Dec 16, 2014, 12:45 AM EST
David SmithRank #999 · 2K reputationPosted Dec 16, 2014, 6:58 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 16, 2014, 7:43 AM EST
That's what you did when 'getting' the value.
David SmithRank #999 · 2K reputationPosted Dec 16, 2014, 7:49 AM EST
David SmithRank #999 · 2K reputationPosted Dec 16, 2014, 8:14 AM EST
public static void SetValue(this DataTable datatable, DataRow datarow, string columnName, int value)
{
try
{
//Standard null exception
if (datatable == null)
throw new ArgumentNullException("datatable", "Datatable is empty.");
//Standard exception if row doesn't belong to this table
if (!datatable.Equals(datarow.Table))
throw new ArgumentException("datarow", "DataRow does not belong to this DataTable.");
//Standard out of range exception for column
if (!datatable.Columns.Contains(columnName))
throw new ArgumentOutOfRangeException("columnName", "Column does not exist.");
datarow.SetField(columnName, value);
datatable.Rows.Add(datarow);
}
catch (Exception ex)
{
throw new Exception("SetValue: \n" + ex.Message);
}
}
VulpesRank #55 · 29.2K reputationPosted Dec 16, 2014, 9:13 AM EST
David SmithRank #999 · 2K reputationPosted Dec 16, 2014, 9:16 AM EST
public static void SetValue(this DataTable datatable, DataRow datarow, string columnName, double value)
{
try
{
//Standard null exception
if (datatable == null)
throw new ArgumentNullException("datatable", "Datatable is null.");
//Standard null exception
if (datarow == null)
throw new ArgumentNullException("datarow", "DataRow is null.");
//Standard exception if row doesn't belong to this table
if (!datatable.Equals(datarow.Table))
throw new ArgumentException("datarow", "DataRow does not belong to this DataTable.");
//Standard out of range exception for column
if (!datatable.Columns.Contains(columnName))
throw new ArgumentOutOfRangeException("columnName", "Column does not exist.");
datarow.SetField(columnName, value);
}
catch (Exception ex)
{
throw new Exception("SetValue: \n" + ex.Message);
}
}
VulpesRank #55 · 29.2K reputationPosted Dec 16, 2014, 9:24 AM EST
I agree that, to be on the safe side, you're best checking that the datarow parameter isn't null.