|
-
February 1st, 2008, 10:45 AM
#1
[RESOLVED] Tables and ImportRow?
Can anyone see what I'm doing wrong I'm getting an ArgumentNullException: Argument column can't be null ?
Code:
...
DataSet ds = testDSet( ...);
result.Tables.Add( ds.Tables[0].Copy() );
result.Tables.Add( ds.Tables[1].Copy() );
//here's the code that generates the error!
result.Relations.Add( result.Tables[0].Columns["CustomerNumber"] , result.Tables[1].Columns["CustomerNumber"] );
...
private static DataSet testDSet(...)
{
...
ds.Tables[0].TableName = "test";
...
ds.Tables.Add("Products");
...
DataSet dsProducts = GetProducts(...)
foreach( DataRow dr2 in dsProducts.Tables[0].Rows )
{
ds.Tables["Products"].ImportRow( dr2 );
}
return ds;
}
-
February 1st, 2008, 10:53 AM
#2
Re: Tables and ImportRow?
My guess would be that in one of those tables you have a dbnull value in the column you are attempting to add the relation on.
-
February 1st, 2008, 11:48 AM
#3
Re: Tables and ImportRow?
Code samples should always meet the minimal yet complete criteria. Yours does not. This makes it impossible to conclusively determine the cause of the error.
For example, you would get this error if either of the tables does not have a column EXACTLY called "CustomerNumber". This is probably the most likely reason. jshultz's post may also be the reason, and there are other potential reasons.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
February 4th, 2008, 08:52 AM
#4
Re: Tables and ImportRow?
Here is the right solution! =)
Code:
...
DataSet ds = testDSet( ...);
result.Tables.Add( ds.Tables[0].Copy() );
result.Tables.Add( ds.Tables[1].Copy() );
DataRelation dr = new DataRelation( "Customernumber" , result.Tables[1].Columns["CustomerNumber"] , result.Tables[2].Columns["CustomerNumber"] );
dr.Nested = true;
result.Relations.Add( dr );
...
private static DataSet testDSet(...)
{
...
ds.Tables[0].TableName = "test";
...
ds.Tables.Add("Products");
...
DataSet dsProducts = GetProducts(...)
int i = 0;
foreach( DataRow dr2 in dsProducts.Tables[0].Rows )
{
if( i == 0 )
{
ds.Tables.Add( dsProducts.Tables[0].Clone() );
}
foreach( DataRow dr2 in dsProducts.Tables[0].Rows )
{
ds.Tables["Products"].ImportRow( dr2 );
}
return ds;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|