C# SQL Data Adapter Fill on existing typed Dataset

Posted by René on Stack Overflow See other posts from Stack Overflow or by René
Published on 2010-04-22T12:44:03Z Indexed on 2010/04/22 12:53 UTC
Read the original article Hit count: 188

Filed under:
|
|
|

I have an option to choose between local based data storing (xml file) or SQL Server based. I already created a long time ago a typed dataset for my application to save data local in the xml file.

Now, I have a bool that changes between Server based version and local version. If true my application get the data from the SQL Server.

I'm not sure but It seems that Sql Adapter's Fill Method can't fill the Data in my existing schema

SqlCommand cmd = new SqlCommand("Select * FROM dbo.Categories WHERE CatUserId = 1", _connection);
                cmd.CommandType = CommandType.Text;

                _sqlAdapter = new SqlDataAdapter(cmd);
                _sqlAdapter.TableMappings.Add("Categories", "dbo.Categories");
                _sqlAdapter.Fill(Program.Dataset);

This should fill my data from dbo.Categories to Categories (in my local, typed dataset). but it doesn't. It creates a new table with the name "Table". It looks like it can't handle the existing schema.

I can't figure it out. Where is the problem?

btw. of course the database request I do isn't very useful that way. It's just a simplified version for testing...

© Stack Overflow or respective owner

Related posts about c#

Related posts about dataset