Overcome the issue of Designer Queries being brittle and being deleted on DataSet changes…
One issue with using Visual Studio designer view for manipulating TableAdapters is that it is very brittle. If you ever delete your tables or change them in your database and update, you loose any custom queries you have made. The below illustrates a way to construct new queries for each TableAdapter in code and thus ensure you do not loose these.
Simply construct a new class and then use the example code below to hard code your queries:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
Option Strict Off Option Explicit On Imports System Namespace gameinfozDataSetTableAdapters Partial Public Class Gi_gameTableAdapter Inherits System.ComponentModel.Component Public Property SelectCommand() As MySql.Data.MySqlClient.MySqlCommand() Get If (Me._commandCollection Is Nothing) Then Me.InitCommandCollection() End If Return Me._commandCollection End Get Set(ByVal value As MySql.Data.MySqlClient.MySqlCommand()) Me._commandCollection = value End Set End Property Public Function FillByWhere(ByVal dataTable As gameinfozDataSet.gi_gameDataTable, ByVal WhereExp As String) As Integer Dim stSelect As String = Nothing stSelect = CommandCollection(0).CommandText Try Me._commandCollection(0).CommandText += " WHERE " + WhereExp Return Me.Fill(dataTable) Catch ex As Exception Finally Me._commandCollection(0).CommandText = stSelect End Try Return 0 End Function End Class End Namespace |
And usage:
Gi_gameTableAdapter.FillByWhere(dbDS.gi_game, "`SystemID` = '" & SysIDString & "'")
Leave a Reply