To go one step further even, when it's this many fields at a time, you
may want to make a class, the represents one row of your data, and have a
public property for each field. The difference between this and a struct
is that you can do additional handling (like checking for field lengths
and ensuring bounds, etc) on each of them.. Because when you have this
much data to update, just doing this field validation can be a handful,
so it might be easier to just save all of that, for this class. for
example:
public string LastName
{
set
{
if ( value.Length > 40 )
throw new Exception("LastName must be less than 40
characters");
m_LastName = value;
}
}
HTH
Nicholas Paldino said:
Nick,
I would recommend creating a structure which exposes public fields
which you can set to the values of each of the columns. The fields
would be named after the columns, of course. Then, you just pass that
in.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
I have a function to update a database table with 40 columns. currently
I created the function with 40 parameters which is very ugly, any best
practice to handle this situation?