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)
{
}
{
}
VulpesPosted Dec 16, 2014, 2:24 PM
I agree that, to be on the safe side, you're best checking that the datarow parameter isn't null.
David SmithPosted Dec 16, 2014, 2:16 PM
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);
}
}
VulpesPosted Dec 16, 2014, 2:13 PM
David SmithPosted Dec 16, 2014, 1:14 PM
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);
}
}
David SmithPosted Dec 16, 2014, 12:49 PM
VulpesPosted Dec 16, 2014, 12:43 PM
That's what you did when 'getting' the value.
David SmithPosted Dec 16, 2014, 11:58 AM
VulpesPosted Dec 16, 2014, 5:45 AM
Joginder BangerPosted Dec 16, 2014, 2:46 AM
i can't understand what's you try. plz explore the problem what's you try or share more code for better understand.