borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Sound in a form)Next Topic (vb.net query) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Dataset related question?
Poster Message
tri_inn
Level: Regular User
Registered: 26-08-2002
Posts: 395

icon Dataset related question?

Please tell me the definition of typed and untyped dataset and what is the difference between typed and untyped dataset.

29-12-2003 at 11:56 AM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Dataset related question?

An untyped dataset is the default kind of dataset that can be used in any situation to get data from any schema. It represents a complete set of data including tables, rows, columns, constraints and relationships. It can contain a number of DataTable objects. It can be used in in coding XML webservices because it represents its data in XML format.

Coding an untyped dataset incurs having to know the names of the tables and the order of the columns. You access data through the Datatable -> DataRow -> DataColumn heirechy.

Typed

A typed dataset is any dataset that is derived from a base Dataset class that applies the information contained in a schema (XSD) to generate a typed class. Information from the schema is compild into a new dataset class derived from the XSD and this makes the Dataset a first class object in the .NET framework. This means that the typed class takes over the functioning of the dataset and can now be used with methods and properties unlike the case with untyped datasets which represent the data as a collection of tables, which are collection of rows, which are collections of columns.

Coding the typed dataset is much easier because you already know the schema unlike making use of the untyped dataset.

Hope this quick description helps. Happy coding...

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

02-01-2004 at 05:44 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
zimcoder
Level: VB Lord


Registered: 27-10-2003
Posts: 225
icon Re: Dataset related question?

Consider:

An "untyped" dataset is an instance of the DataSet class from the System.Data namespace. It's called "untyped" because all columns are provided as the base System.Object type ("object" in C# and "Object" in VB.NET) and must be coerced to the appropriate type. For example:

void Form1_Load(object sender, EventArgs e) {
  DataSet ds = new DataSet();
  sqlDataAdapter1.Fill(ds);
  foreach( DataRow row in ds.Tables[0].Rows ) {
    string fname = (string)row["au_fname"];
    bool contract = (bool)row["contract"];
    string item =
      string.Format("{0} has a contract: {1}", fname, contract);
    listBox1.Items.Add(item);
  }
}


The problem, of course, is that it's a pain to get the coercion code. It is tedious to write and easy to get wrong. A type-safe dataset, on the other hand, allows you to write the following code:

void Form1_Load(object sender, EventArgs e) {
  AuthorsDataSet ds = new AuthorsDataSet();
  sqlDataAdapter1.Fill(ds);
  foreach( AuthorsDataSet.authorsRow row in ds.authors.Rows ) {
    string fname = row.au_fname;
    bool contract = row.contract;
    string item =
      string.Format("{0} has a contract: {1}", fname, contract);
    listBox1.Items.Add(item);
  }
}


In this case, notice that we have a new type, AuthorsDataSet. It derives from the DataSet base type and provides type-safe access to each column in each row via the authorsRow nested type and the authors property on the filled AuthorsDataSet. Now we can simply access the columns as if they were fields without any type coercion code.
There are several ways to get a type-safe DataSet, but the easiest starts with the Solution Explorer (View -> Solution Explorer). The Solution Explorer allows you to explore the SQL Servers you've got on your network as well as establish connections to other OLE DB-compliant data sources. Once you've navigated to the database you're interested in, you can drag a table onto any designer surface, including a WinForm or a WebForm, which will create a connection object and an adapter object, the former for connecting to the database and the latter for filling the DataSet. To generate a type-safe DataSet-derived class, choose Data -> Generate Dataset, entering the name of the type-safe DataSet that you'd like. Since I'm lazy, I prefer to use type-safe DataSet classes all the time, saving me the trouble of writing the type coercion code.


____________________________
BrainBench ADO.NET and ASP.NET Certified Developer

07-01-2004 at 03:37 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Dataset related question?
Previous Topic (Sound in a form)Next Topic (vb.net query) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder