I've encountered a rather puzzling problem with SqlDataAdapter. I've set up a number of elaborate tables in the Microsoft SQL Server Management Studio Express (including several table key relationships), and I've been successfully accessing all of that information through the classes generated by the "visual" DataSet file in Web Developer Express (Solution > Add New Item > Data Set).
Prior to my last code modification I've successfully read the SQL table relationships from DataSet.Relations, or, in my case, ProjectsDataSet.Relations (my main table is called "Projects", ProjectsDataSet was generated by Web Developer Express).
For the next step of my project I had to abandon the classes from the "visual" DataSet files, such as ProjectsDataSet and ProjectsDataAdapter, and start making the program work with generalized DataSets, SqlDataAdapters and SqlConnections.
So instead of relying on the classes from the DataSet file, I began to feed my application the following manually created instances:
Expand|Select|Wrap|Line Numbers
- string tableName = "Projects";
- SqlConnection connection = new SqlConnection( connectionString );
- DataSet dataSet = new DataSet();
- SqlDataAdapter dataAdapter = new SqlDataAdapter( "select * from " + tableName, connection );
- SqlCommandBuilder b = new SqlCommandBuilder( dataAdapter );
- dataAdapter.Fill( dataSet, tableName );
What's worse, the AllowDBNull properties of my DataColumns are all "true" even though most of my columns don't allow null values. I've explicitly set the column properties in MS Server Management Studio!
It seems that unlike the ProjectsDataSet class that was created by Visual Web Developer, the manually-allocated DataSet object isn't pulling all information out of the database definitions.
Any ideas?