Please help me with this question.

That's multiple choice questions.

Which of the following are true about using ADO.NET DataSets and DataTables?

1) The connection to the database must remain valid for the life of the data objects.
2) All tables in a dataset must come from the same database.
3) A given instance of a DataTable can be in only one DataSet
4) Changes made to multiple tables within a DataSet can easily be extracted to a new DataSet which contains only the changes.
5) Content from multiple DataSets can easily be combined into a single DataSet that contains the net result of all changes.

One of those two is correct.

Also can there only be one answer or is there more? I think one more might be true.

One of those two is correct.

Also can there only be one answer or is there more? I think one more might be true.

I think both #2 and #3 are correct.. I said it's a multiple choice question, more than one are correct. Thanks anyway.

#2 is not correct. DataTables do not have to come from a database at all --- you can generate them in code. You could also pull data from 2 databases. DataSet's only care about the data they have in memory and their relationship+constraints, not the source.

#2 is not correct. DataTables do not have to come from a database at all --- you can generate them in code. You could also pull data from 2 databases. DataSet's only care about the data they have in memory and their relationship+constraints, not the source.

After thinking a little I came to this:: correct answers are #3 ad #4.

What do you think??

1) The connection to the database must remain valid for the life of the data objects.
- true
2) All tables in a dataset must come from the same database.
-false
3) A given instance of a DataTable can be in only one DataSet
-false
4) Changes made to multiple tables within a DataSet can easily be extracted to a new DataSet which contains only the changes.
-true
5) Content from multiple DataSets can easily be combined into a single DataSet that contains the net result of all changes.
-true

1) The connection to the database must remain valid for the life of the data objects.
- true
2) All tables in a dataset must come from the same database.
-false
3) A given instance of a DataTable can be in only one DataSet
-false
4) Changes made to multiple tables within a DataSet can easily be extracted to a new DataSet which contains only the changes.
-true
5) Content from multiple DataSets can easily be combined into a single DataSet that contains the net result of all changes.
-true

serkan,
1) .NET uses disconnected datasets. They close right after they're done getting data. (Unless you go out of your way to stop them. This is the default behavior)
3)

private void button11_Click(object sender, EventArgs e)
    {
      try
      {
        DataSet ds1 = new DataSet();
        DataSet ds2 = new DataSet();

        DataTable dt = new DataTable();
        dt.Columns.Add("Field1", typeof(string));
        dt.Columns.Add("Field2", typeof(string));
        DataRow row = dt.NewRow();
        row["Field1"] = "val1";
        row["Field2"] = "val2";
        dt.TableName = "Test";

        ds1.Tables.Add(dt);
        ds2.Tables.Add(dt);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Message: " + ex.Message);
        Console.WriteLine("Source: " + ex.Source);
      }
    }

Results in:

A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll
Message: DataTable already belongs to another DataSet.
Source: System.Data

5) You can't very well combine multiple datasets as they could have different definitions. IE DataSet1 has a "Jobs" table from DataBase "Employer" and DataSet2 has a "Jobs" table from DataBase "Hiring". This could get very hairy real fast in trying to aggregate their changes.

>1) .NET uses disconnected datasets. They close right after they're done getting data. (Unless you go out of your way to stop them. This is the default behavior)
validity of connection refers to Connection object properties, e.g your connection string and etc. those must be valid.

This article has been dead for over six months. Start a new discussion instead.