Table Names
-
I'm using SQL 2005 Express, and VC#2005 Express. Using a SQLCommand.ExecuteNonQuery() with a CREATE TABLE statement, I can make a table in my database with the columns I need, determined at runtime. I've verified the table is made in the database correctly, via SQL server Management Studio Express. In the process of making the CREATE TABLE statement, I also make the table in my local DataSet, same name, same columns, should be identical, along with a DataAdapter for the table. However, when I try to DataAdapter.Fill() the table, it tells me the table name is invalid, like the table isn't in the database on disk. I've tried setting the MissingSchema property to PassThrough, and then the .Fill() makes a new table, same columns, keys, etc., but the name of the new table is "Table", not the table name I create it with. Any help on this, either the table isn't being made right, or the DataAdapter is screwing up somehow, I can't figure it out. My CREATE TABLE statement CREATE TABLE finished (Listing NOT NULL PRIMARY KEY IDENTITY(1000,1),[More data columns, shouldn't be the problem, just data]) The SELECT statement used in DataAdapter SELECT Listing,[More columns as above] FROM finished I can post the code if needed
A soft glow comes from the pit in the darkness. The clicking noise become faster - and louder. A wind begins to stir up from the pit, as the creature flexes it's wings, preparing for flight. You stare into the pit, and hear a voice say in your mind, "If you survive the encounter, declare it to the world." The Code Demon Rises.
-
I'm using SQL 2005 Express, and VC#2005 Express. Using a SQLCommand.ExecuteNonQuery() with a CREATE TABLE statement, I can make a table in my database with the columns I need, determined at runtime. I've verified the table is made in the database correctly, via SQL server Management Studio Express. In the process of making the CREATE TABLE statement, I also make the table in my local DataSet, same name, same columns, should be identical, along with a DataAdapter for the table. However, when I try to DataAdapter.Fill() the table, it tells me the table name is invalid, like the table isn't in the database on disk. I've tried setting the MissingSchema property to PassThrough, and then the .Fill() makes a new table, same columns, keys, etc., but the name of the new table is "Table", not the table name I create it with. Any help on this, either the table isn't being made right, or the DataAdapter is screwing up somehow, I can't figure it out. My CREATE TABLE statement CREATE TABLE finished (Listing NOT NULL PRIMARY KEY IDENTITY(1000,1),[More data columns, shouldn't be the problem, just data]) The SELECT statement used in DataAdapter SELECT Listing,[More columns as above] FROM finished I can post the code if needed
A soft glow comes from the pit in the darkness. The clicking noise become faster - and louder. A wind begins to stir up from the pit, as the creature flexes it's wings, preparing for flight. You stare into the pit, and hear a voice say in your mind, "If you survive the encounter, declare it to the world." The Code Demon Rises.
Replying to my own post... In case anyone else has this problem, here's how I figured this out. Simple really. I just needed to add a TableMapping to the DataAdapter, and give it the right names. One line of code fixed a 3 day problem. myDataAdapter.TableMappings.Add( "Table", myTable.TableName ); Have Fun!
A soft glow comes from the pit in the darkness. The clicking noise become faster - and louder. A wind begins to stir up from the pit, as the creature flexes it's wings, preparing for flight. You stare into the pit, and hear a voice say in your mind, "If you survive the encounter, declare it to the world." The Code Demon Rises.
-
Replying to my own post... In case anyone else has this problem, here's how I figured this out. Simple really. I just needed to add a TableMapping to the DataAdapter, and give it the right names. One line of code fixed a 3 day problem. myDataAdapter.TableMappings.Add( "Table", myTable.TableName ); Have Fun!
A soft glow comes from the pit in the darkness. The clicking noise become faster - and louder. A wind begins to stir up from the pit, as the creature flexes it's wings, preparing for flight. You stare into the pit, and hear a voice say in your mind, "If you survive the encounter, declare it to the world." The Code Demon Rises.
If you really want to be slick and save some work you could create the table as a datatable first then use SqlServer Management Objects to create the table at run time based on your in memory datatable. This only works with Sql2005 and Express2005, but it really save time in the code and verifies that what you have in memory matches with the database. If you are interested: http://www.codeproject.com/useritems/DataTableToDataBase.asp[^] Yes, this is one of my articles( currently my only one as I have been swamped) but SMO has become a pet project of mine as I am fascinated by it. Take a look and see if it helps. Aaron
_____________________________________________________________________ Our developers never release code. Rather, it tends to escape, pillaging the countryside all around. The Enlightenment Project (paraphrased comment) Visit Me at GISDevCafe