G
Guest
Hi,
I would just like to advice on how to fix a problem I'm having in adding a
new row to a DataTable.
Anyway, my problem is that this code always gives me the dreaded "object
reference not set to an instance" exception:
[C#] (WinForms)
DataRow row;
row = DataSet.Tables[0].NewRow();
// set row column values here
DataSet.Tables[0].Rows.Add(row); //<< exception on this line
I've check on the values for DataSet, Tables[0], Tables[0].Rows and row...
They all have valid values, so how come the exception is thrown?
I've also tried something like:
DataRow row;
DataTable table = DataSet.Tables[0];
row = table.NewRow();
//set column values here
table.Rows.Add(row) //<< exception still gets thrown here
I'm using Visual Studio 2003 with .NET framework sp1 installed on Windows XP
professional with SP2...
The funny thing is that within the same event, but under the code for a
different "case" block, i have a similar set of code for a different table
within the same dataset but the exception doesn't get thrown during the
Rows.Add portion.
One more thing, this wasn't a problem when the .NETFX SP1 wasn't installed
yet.
I would really appreciate any insight anyone can give on this, we really
need to install SP1, because of certain fixes that it introduced.
I'm thinking maybe some of the Post-SP1 "hotfixes" might address this
problem, but I don't know which.
BTW, there's someone else who encountered a similar error, he's already
posted his problem on several forums last October 2004 and there's no reply
to his post, I'm just not sure if he has SP1 installed. Links to his posts
are
http://www.techietwo.com/detail-6334024.html[/URL
[URL]http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic2591.aspx
you can also try searching for "datatable.insertrow object reference" on
google groups, it's one of the 2 posts that will be shown in the search
results.
TIA.
raist[/URL]
I would just like to advice on how to fix a problem I'm having in adding a
new row to a DataTable.
Anyway, my problem is that this code always gives me the dreaded "object
reference not set to an instance" exception:
[C#] (WinForms)
DataRow row;
row = DataSet.Tables[0].NewRow();
// set row column values here
DataSet.Tables[0].Rows.Add(row); //<< exception on this line
I've check on the values for DataSet, Tables[0], Tables[0].Rows and row...
They all have valid values, so how come the exception is thrown?
I've also tried something like:
DataRow row;
DataTable table = DataSet.Tables[0];
row = table.NewRow();
//set column values here
table.Rows.Add(row) //<< exception still gets thrown here
I'm using Visual Studio 2003 with .NET framework sp1 installed on Windows XP
professional with SP2...
The funny thing is that within the same event, but under the code for a
different "case" block, i have a similar set of code for a different table
within the same dataset but the exception doesn't get thrown during the
Rows.Add portion.
One more thing, this wasn't a problem when the .NETFX SP1 wasn't installed
yet.
I would really appreciate any insight anyone can give on this, we really
need to install SP1, because of certain fixes that it introduced.
I'm thinking maybe some of the Post-SP1 "hotfixes" might address this
problem, but I don't know which.
BTW, there's someone else who encountered a similar error, he's already
posted his problem on several forums last October 2004 and there's no reply
to his post, I'm just not sure if he has SP1 installed. Links to his posts
are
http://www.techietwo.com/detail-6334024.html[/URL
[URL]http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic2591.aspx
you can also try searching for "datatable.insertrow object reference" on
google groups, it's one of the 2 posts that will be shown in the search
results.
TIA.
raist[/URL]