Hi.
Creating a .NET DataSet is easy with Visual Studio, but there is no way to expose that object from a shared DLL. Indeed, when we use only one EXE, we have the same problem: dynamically changing the Dataset ConnectionString which is only a parameter does not seem natural: we traffic a value inked in the assembly!? In addition, the same dataset can be used to manipulate different databases at the same time, which is in contradiction with the existence of a single variable usage (a connectionstring of the project resource).
So I wanted your opinion on the issue, although from my side I found an idea that does not satisfy me because I find it wobbly.
What I have tried:
My current solution : search and replace every " friend" by " public" in dataset designer file, to be able to use a reflexion code based on TableName value, to predict TableAdapter object Name, to dynamically create a new TableAdapter instance from real one, and pass a connexion as parameter already managed before this.
#Region "Dataset"
Public Function TableAdapterRoot(_Name As String) As String
Dim szRootObject As String = "ECI_Data." & _type.ToString & "_DataSet"
szRootObject &= "_" & _Version.Major & "TableAdapters."
szRootObject &= _Name & "TableAdapter"
Return szRootObject
End Function
Public Function ChargerTable(_TableName As String, Optional ByVal Reload As Boolean = False, Optional ByVal clone As Boolean = False) As DataTable
Dim _ClassName As String
Dim _Adapter As Object
Try
If Not Reload And DataSet.Tables(_TableName).Rows.Count > 0 Then
ChargerTable = DataSet.Tables(_TableName)
Exit Function
End If
_ClassName = TableAdapterRoot(_TableName)
_Adapter = System.Reflection.Assembly.GetExecutingAssembly.CreateInstance(_ClassName)
_Adapter.Connection = _Connexion
_Adapter.Transaction = _Transaction
Dim dt As DataTable = Nothing
If clone Then
dt = DataSet.Tables(_TableName).Clone
Else
dt = DataSet.Tables(_TableName)
End If
_Adapter.Fill(dt)
ChargerTable = dt
_Adapter.dispose()
Catch ex As Exception
MessageErreur("(Table [" & _TableName & "] " & ex.Message)
ChargerTable = Nothing
End Try
End Function
#end region
i wish someone have a better solution, because, this is not a solution, to manually edit the content of the dataset designer after each automatic update of the dataset designer.