Actually the answer is technically yes. If the question were worded using
the word "easily" then the answer would be no.
I use them all the time. First I model them in .NET then rip out all the the
stuff that CF.NET chokes on. The follow code, although 'junky' and
uneditted, still works. Pass in the dataset.vb file and the path to your new
CF.NET dataset.vb file.
Change the 'Insight...' namespace where needed. Also note that if you have
a timestamp field you might want to ommit it from you DataSet entirely like I
did with the 'TS' field.
Good luck.
Get ready to roll your selves up. (International Translation: This could be
difficult)
=====================================
Sub buildCeBusinessEntity(ByVal f1 As String, ByVal f2 As String)
Dim sw As StreamWriter = New StreamWriter(f2)
Dim sr As StreamReader = New StreamReader(f1)
Dim line As String
Dim line2 As String = ""
Dim newLine As String
Console.Write(f1)
Do
line = sr.ReadLine()
If Not line Is Nothing Then
'Console.WriteLine(line.Trim)
'Threading.Thread.CurrentThread.Sleep(1000)
Select Case line.Trim.ToLower
Case "Imports System".ToLower
newLine = line
sw.WriteLine("Imports Insight.Pocket.Common") ' For
StrongTypeException et al.
Case "<Serializable(), _".ToLower
newLine = " < _"
Case "System.Diagnostics.DebuggerStepThrough(),
_".ToLower
newLine = "
System.Diagnostics.DebuggerStepThrough()> _"
Case "System.ComponentModel.ToolboxItem(true)> _".ToLower
newLine = Nothing
Case "Protected Sub New(ByVal info As SerializationInfo,
ByVal context As StreamingContext)".ToLower
' Skip to end of function
While line2.Trim <> "End Sub"
line2 = sr.ReadLine
End While
newLine = ""
Case "<System.ComponentModel.Browsable(False), _".ToLower
newLine = ""
Case
"System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)> _".ToLower
newLine = ""
Case "Protected Overrides Sub ReadXmlSerializable(ByVal
reader As XmlReader)".ToLower
line2 = ""
'skip to end of function
While line2.Trim <> "End Sub"
line2 = sr.ReadLine
End While
newLine = ""
Case "Protected Overrides Function
GetSchemaSerializable() As System.Xml.Schema.XmlSchema".ToLower
line2 = ""
'skip to end of function
While line2.Trim <> "End Function"
line2 = sr.ReadLine
End While
newLine = ""
Case "<System.ComponentModel.Browsable(False)>
_".ToLower, "<System.ComponentModel.Browsable(True)> _".ToLower
newLine = ""
Case "Protected Overrides Function CreateInstance() As
DataTable".ToLower
newLine = " Protected Function CreateInstance() As
DataTable"
Case "Inherits DataSet".ToLower
newLine = "Inherits BaseDataSet"
Case Else
newLine = line
End Select
If Not line Is Nothing Then
If line.Trim.Length > 42 Then
If line.Trim.StartsWith("Me.Constraints.Add(New
UniqueConstraint") Then
Dim endAt As Integer = line.IndexOf(", true")
Dim startAt As Integer = line.IndexOf(""", ") + 2
line = line.Replace(", true", "")
line &= vbCrLf & "Me.PrimaryKey = " &
line.Substring(startAt, endAt - startAt)
newLine = line
End If
End If
If InStr(line, "TS") Then
If InStr(line, "Me.columnTS.ReadOnly = true") Then
newLine = Nothing
ElseIf InStr(line, "ByVal TS() As Byte, _") Then
newLine = Nothing
ElseIf InStr(line, "Private columnTS As DataColumn")
Then
newLine = Nothing
ElseIf InStr(line, "Public Property TS As Byte()")
Then
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
newLine = Nothing
ElseIf InStr(line, "TSNull()") Then
sr.ReadLine()
sr.ReadLine()
newLine = Nothing
ElseIf InStr(line, "Friend ReadOnly Property
TSColumn As DataColumn") Then
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
newLine = Nothing
ElseIf InStr(line, "Me.columnTS =
Me.Columns(""TS"")") Then
newLine = Nothing
ElseIf InStr(line, "Me.columnTS = New
DataColumn(""TS"", GetType(System.Byte()), Nothing,
System.Data.MappingType.Element)") Then
sr.ReadLine()
newLine = Nothing
ElseIf InStr(line, "Friend Sub New()") Then
newLine = "Public Sub New()" ' For use of Clone
method
ElseIf InStr(line, ", TS") Then
newLine = line.Replace(", TS", "")
End If
End If
End If
If InStr(line, "Friend Sub New()") Then
newLine = "Public Sub New()"
End If
If InStr(line, "Date.Parse(""" & Now.ToString("M/d/yyyy") &
" 12:00:00 PM"")") Then
newLine = line.Replace("Date.Parse(""" &
Now.ToString("M/d/yyyy") & " 12:00:00 PM"")", "Date.Parse(""1/01/0001
12:00:00 AM"")") 'Remember SQLCE MinDate is different
End If
If Not newLine Is Nothing Then
sw.WriteLine(newLine)
End If
'Console.WriteLine(newLine)
End If
Loop Until line Is Nothing
sr.Close()
sw.Close()
End Sub
=====================================
BaseDataSet.vb (I cannot take all the credit for this but also cannot
remember where the credit is due)
---------------------------------------
Public Class BaseDataSet
Inherits Data.DataSet
Public Sub New()
MyBase.New()
Me.CaseSensitive = True
End Sub
Public Sub New(ByVal dataSetName As String)
MyBase.New(dataSetName)
Me.CaseSensitive = True
End Sub
Public Overridable Function GetChanges(ByRef ds As Data.DataSet, ByVal
rowStates As System.Data.DataRowState) As Data.DataSet
' dataset that is returned
Dim dsChanges As Data.DataSet ' = ds.Clone
'add table
'dsChanges.Tables.Add(ds.Tables(0).Clone)
'loop through table and find changes
For Each row As Data.DataRow In ds.Tables(0).Rows
If row.RowState = rowStates Then
If dsChanges Is Nothing Then dsChanges = ds.Clone
dsChanges.Tables(0).ImportRow(row)
End If
Next
Return dsChanges
End Function
Public Overridable Function GetChanges(ByRef ds As Data.DataSet) As
Data.DataSet
'dataset that is returned
Dim dsChanges As Data.DataSet = ds.Clone
'add table
dsChanges.Tables.Add(ds.Tables(0).Clone)
' loop through table and find changes
For Each row As Data.DataRow In ds.Tables(0).Rows
If row.RowState = Data.DataRowState.Added OrElse row.RowState =
Data.DataRowState.Deleted OrElse row.RowState = Data.DataRowState.Modified
Then
dsChanges.Tables(0).ImportRow(row)
End If
Next
Return dsChanges
End Function
End Class
============================
StrongTypingException.vb
--------------------------
Public Class StrongTypingException
Inherits Exception
Sub New(ByVal message As String, ByVal innerException As Exception)
MyBase.New(message, innerException)
End Sub
Sub New(ByVal message As String)
MyBase.New(message)
End Sub
End Class
"Ilya Tumanov [MS]" said:
Typed DataSets are not supported on CF V1, sorry.
You can modify proxy code to use untyped DataSet instead.
Or, you can remove unsupported stuff form typed DataSet code so you can
compile it against CF.
The problem with that is what you would have to modify the code each time
proxy is regenerated.
By the way, it's not clear to me how exactly you're getting
TypeLoadException.
It should be impossible to compile proxy class for WS using typed DataSet's.
Are you compiling against desktop and trying to run this code on device?
If so, it won't work.
Best regards,
Ilya
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Reply-To: "Joakim Englund" <
[email protected]>
From: "Joakim Englund" <
[email protected]>
Subject: Strongly typed datasets and .NET CF = System.TypeLoadException?
Date: Thu, 12 Aug 2004 16:43:52 +0200
Lines: 16
Organization: INTRESS
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <
[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: ns.intress.se 193.15.233.39
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:59247
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
Hi all!
Is it possible to use strongly typed datasets in .NET CF.
I'm calling a web service from a smart device application running on P PC
2002 that returns a strongly typed dataset. Immediately when the call is
made I get a System.TypeLoadException. If I run the same application on
Windows XP I don't get any exception and the strongly typed dataset is
displayed correctly.
Thanks in advance for any help on this issue.
BR
Joakim