473,763 Members | 6,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataTable: Corrupted SQL Table Properties with generalized SqlDataAdapter?

16 New Member
Hello,

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.Relatio ns, 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 ProjectsDataAda pter, 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
  1. string tableName = "Projects";
  2.  
  3. SqlConnection connection = new SqlConnection( connectionString );
  4.  
  5. DataSet dataSet = new DataSet();
  6. SqlDataAdapter dataAdapter = new SqlDataAdapter( "select * from " + tableName, connection );
  7. SqlCommandBuilder b = new SqlCommandBuilder( dataAdapter );
  8. dataAdapter.Fill( dataSet, tableName );
  9.  
Suddenly my program no longer detects any relations in the DataSet, even though it comes from the exact same source as the one that I allocated "by hand" instead of using the DataSet file. The DataSet.Relatio ns list has no elements at all.

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?
Apr 17 '07 #1
3 1648
iburyak
1,017 Recognized Expert Top Contributor
Microsoft is famous to call this type of programming as disconnected datasets.
It makes intelligent assumption on data structure but not actual like allow null values where they are not allowed in underlying database. I am sure you will not be able to save this dataset to a database with null value in a column.
First time - you linked to the database and this time - you imported data and created your own disconnected database that is independent from the server.
This way it is easy to import XML and SQL data into the same DataAdapter and join together seamlessly.

For more info check this:
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson05.aspx

Sorry not sure how to help you here.

Irina.
Apr 17 '07 #2
Spectre1337
16 New Member
Thanks. I had already read through that page and actually based parts of my program on it.

Is there another elegant way to retrieve table/column information, like AllowDBNull or Relations, other than looking at the DataColumn object of the DataTable?
Apr 17 '07 #3
Spectre1337
16 New Member
Just in case anyone is having the same problem, after a long and annoying search I've finally found a solution:

You need to generate an XSD database schema file using Web Developer Express (Or by any other means) and then,prior to Fill(), load it into the DataSet using ReadXmlSchema() .
Apr 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6798
by: Luis Esteban Valencia | last post by:
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0117: 'System.Data.DataTable' does not contain a definition for 'WriteXml' Source Error:
10
6541
by: dauphian | last post by:
Hello, I am new to .net and am trying to build a report application that queries 4 different tables based on a id, and I need to return them in the same table for easy viewing. Basically, I have one querie that grabs all of the id's I need for the other 4 queries, but I am not sure how to get them into a DataTable or DataSet, or if that is the best way to do this. Seperately the queries all work with no problems.
1
2089
by: andrewcw | last post by:
I have just 1 table that I am updating, the SQL I use to generate the DataTable is complex using multiple tables, however when I view the fieldnames of the DataTable from the DataSet - everything matches: What dont I understand here: ( The error I get is : Dynamic SQL generation is not supported against multiple base tables ). But My DataSet is 1 Table, and my target is 1 table, Why the error ?? Thanks : try {
9
6988
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table population. Whenever I call the thread, I pass it a structure containing the table and a few other parameters. The table goes in as a reference, but the other items are passed normally.
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.