[2008] Untyped vs strongely typed
Hi
I have made a lot of search to know about the difference between untyped and strongelytyped dataset or untyped and strongelytyped classes but i didn't understand well the concept.
can anyone give me a clear explanation about the difference?
thanks
Re: [2008] Untyped vs strongely typed
Using a strongly typed data set will give you extended intellisence for your data set, and will do type conversion for you. Example
Code:
'generic dataset
For Each row as DataRow in myDataSet.Tables("Table1").Rows
Dim myString As String = CStr(row.Item("myString"))
Next
Code:
'Strongly Typed dataset
For Each row as myDataSet.Table1DataRow in myDataSet.Table1.Rows
Dim myString As String = row.myString
Next
Re: [2008] Untyped vs strongely typed
Each field in each row of each table in a typed DataSet is exposed via a property of a particular type. As such the compiler will do all the type checking for you and tell you at compile time if you're assigning a value of the wrong type to a field in a row.
Each field in each row of each table in an untyped DataSet is exposed via the Item property and is type Object, because it has to able to accept any type of object. As such, you won't find out until run time if you've assigned a value of the wrong type to a field, when an exception is thrown.
Note also that a typed DataSet creates TableAdapters for you, which are essentially a typed DataAdapter. All the SQL code and connection details are contained within the TableAdapter so you don't have to write the code yourself. Each TableAdapter is paired with a typed DataTable. The SQL code in the TableAdapter is matched to the schema of the DataTable so they are always used together.