PC Review


Reply
Thread Tools Rate Thread

DataAdapter Mapping only works for the first two tables.

 
 
vrjaya@hotmail.com
Guest
Posts: n/a
 
      29th Nov 2005
Hi,

I am writing an application where the select command returns multiple
record sets and write the infomation to a xml file. I used typed
dataset to store the returned info and use the dataset.writexml command
to save the data to a xml file. Oh one more thing I am used the DAB
(data application block) to fill the dataset. I tried the same solution
with the "Northwind" database but no luck.

Here's my code:

SQL stroed proc:

CREATE PROCEDURE [dbo].[proc_name]
@EmployeeID INT
AS

SELECT * FROM Employees
WHERE EmployeeID = @EmployeeID;

SELECT * FROM EmployeeTerritories;

SELECT * FROM Territories;

GO

Here's the code that fills the dataset:

TestDto dto = new TestDto(); //xsd contains the tables def
string[] tableList = new string[3] ;
tableList[0] = "Employees";
tableList[1] = "EmployeeTerritories";
tableList[2] = "Territories";

SqlHelper.FillDataset("connectionstring", CommandType.StoredProcedure,
"proc_name", dto, tableList, new SqlParameter("@EmployeeID", 1) );

dto.WriteXml(@"C:\xxx.xml");

When I look at the "xxx.xml" file i see the table mapping being done
for "Employees" and "EmployeeTerritories" but "Territories" mapping is
set to "Table2"...Crazy!!!!

Can someone please tell me why?

 
Reply With Quote
 
 
 
 
Sahil Malik [MVP]
Guest
Posts: n/a
 
      29th Nov 2005
Can you verify your TableMappings right before the Fill?

Also is this .NET 1.1 or 2.0?


--

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
----------------------------------------------------------------------------



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I am writing an application where the select command returns multiple
> record sets and write the infomation to a xml file. I used typed
> dataset to store the returned info and use the dataset.writexml command
> to save the data to a xml file. Oh one more thing I am used the DAB
> (data application block) to fill the dataset. I tried the same solution
> with the "Northwind" database but no luck.
>
> Here's my code:
>
> SQL stroed proc:
>
> CREATE PROCEDURE [dbo].[proc_name]
> @EmployeeID INT
> AS
>
> SELECT * FROM Employees
> WHERE EmployeeID = @EmployeeID;
>
> SELECT * FROM EmployeeTerritories;
>
> SELECT * FROM Territories;
>
> GO
>
> Here's the code that fills the dataset:
>
> TestDto dto = new TestDto(); //xsd contains the tables def
> string[] tableList = new string[3] ;
> tableList[0] = "Employees";
> tableList[1] = "EmployeeTerritories";
> tableList[2] = "Territories";
>
> SqlHelper.FillDataset("connectionstring", CommandType.StoredProcedure,
> "proc_name", dto, tableList, new SqlParameter("@EmployeeID", 1) );
>
> dto.WriteXml(@"C:\xxx.xml");
>
> When I look at the "xxx.xml" file i see the table mapping being done
> for "Employees" and "EmployeeTerritories" but "Territories" mapping is
> set to "Table2"...Crazy!!!!
>
> Can someone please tell me why?
>



 
Reply With Quote
 
vrjaya@hotmail.com
Guest
Posts: n/a
 
      2nd Dec 2005
Hi Sahil,

When i debug i saw the table mapping being done via the data adapter,
After the fill the first two tables are mapped fine but not after.
Sahil Malik [MVP] wrote:
> Can you verify your TableMappings right before the Fill?
>
> Also is this .NET 1.1 or 2.0?
>
>
> --
>
> - Sahil Malik [MVP]
> ADO.NET 2.0 book -
> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
> ----------------------------------------------------------------------------
>
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > I am writing an application where the select command returns multiple
> > record sets and write the infomation to a xml file. I used typed
> > dataset to store the returned info and use the dataset.writexml command
> > to save the data to a xml file. Oh one more thing I am used the DAB
> > (data application block) to fill the dataset. I tried the same solution
> > with the "Northwind" database but no luck.
> >
> > Here's my code:
> >
> > SQL stroed proc:
> >
> > CREATE PROCEDURE [dbo].[proc_name]
> > @EmployeeID INT
> > AS
> >
> > SELECT * FROM Employees
> > WHERE EmployeeID = @EmployeeID;
> >
> > SELECT * FROM EmployeeTerritories;
> >
> > SELECT * FROM Territories;
> >
> > GO
> >
> > Here's the code that fills the dataset:
> >
> > TestDto dto = new TestDto(); //xsd contains the tables def
> > string[] tableList = new string[3] ;
> > tableList[0] = "Employees";
> > tableList[1] = "EmployeeTerritories";
> > tableList[2] = "Territories";
> >
> > SqlHelper.FillDataset("connectionstring", CommandType.StoredProcedure,
> > "proc_name", dto, tableList, new SqlParameter("@EmployeeID", 1) );
> >
> > dto.WriteXml(@"C:\xxx.xml");
> >
> > When I look at the "xxx.xml" file i see the table mapping being done
> > for "Employees" and "EmployeeTerritories" but "Territories" mapping is
> > set to "Table2"...Crazy!!!!
> >
> > Can someone please tell me why?
> >


 
Reply With Quote
 
=?Utf-8?B?U2hhdW5NYw==?=
Guest
Posts: n/a
 
      6th Feb 2006
Having had the same issue, I found that there is a bug in the Microsoft Data
Access Application Block for c# in the filldataset method.

The table mappings are added incorrectly and named as follows

Table
Table1
Table12
Table123
Table1234
etc.

But it should read

Table
Table1
Table2
Table3
Table4
etc.


One way of fixing this, is to reassign the tableName sting to "Table" before
the tableName is set for the next iteration of the loop.

// Add the table mappings specified by the user
if (tableNames != null && tableNames.Length > 0)
{
string tableName = "Table";
for (int index=0; index < tableNames.Length; index++)
{
if( tableNames[index] == null || tableNames[index].Length == 0 )
throw new ArgumentException( "The tableNames parameter must contain a list of
tables, a value was provided as null or empty string.", "tableNames" );

dataAdapter.TableMappings.Add(tableName, tableNames[index]);
tableName = "Table";
tableName += (index + 1).ToString();
}
}

regards

Shaun


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dataAdapter not updating - but sqlcommand works OK =?Utf-8?B?UmljaA==?= Microsoft ADO .NET 8 4th Feb 2006 06:44 PM
Mapping Columns w/o DataAdapter? Bostonasian Microsoft ADO .NET 4 17th Jun 2005 09:48 AM
DataAdapter.Update works w/ datagrid but not w/ textboxes johnb41 Microsoft VB .NET 2 2nd Mar 2005 08:14 PM
How to identify the tables in a dataAdapter? Geoff Pennington Microsoft VB .NET 6 11th Nov 2003 08:15 PM
Dynamic ConnectionString in DataAdapter only works with appSettings ? heikekrieg Microsoft ADO .NET 5 24th Jul 2003 10:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:29 AM.