This question may have been asked and answered before, but I do not know how to search for it.
The situation:
I have a Winforms
application with many bound controls. We have four testing environments and currently, I have been connecting to each data source and importing all data tables and stored procedures using the Data Source Configuration Manager
then having the connection string information stored in my app.config file. When I call the connection string, I am using My.Settings.[connection string name].ToString (my first problem).
For all data bound controls (mostly datagridview
), I remove the old data set + the table adapter and all binding sources before dragging the new data set + table adapter and binding sources. I have a Public Sub
that clears and rebinds all of my controls, but the code calls for the specific name of each data source (see below for example).
Public Sub SetRegionDEBindings(ByVal errorCode As String, ByVal Region As String)
Try
Dim selectLOMAbyRegion As New BindingSource
selectLOMAbyRegion = Me.SpSelectLOMABindingSource
Me.SpSelectLOMATableAdapter.Fill(Me.PrdGISDataSet.spSelectLOMA, errorCode, Region)
Me.dgDE.DataSource = selectLOMAbyRegion
Me.bnDE.BindingSource = selectLOMAbyRegion
Me.txtDEIssueDte.DataBindings.Add(New System.Windows.Forms.Binding("Text", selectLOMAbyRegion, "IssueDte", True))
Me.txtDECaseNum.DataBindings.Add(New System.Windows.Forms.Binding("Text", selectLOMAbyRegion, "CaseNum", True))
Me.txtDECommNum.DataBindings.Add(New System.Windows.Forms.Binding("Text", selectLOMAbyRegion, "CommNum", True))
With Me.dgDE
Me.DataGridViewTextBoxColumn1.Name = "DERegion"
Me.StateDataGridViewTextBoxColumn.Name = "DEState"
Me.LatitudeDataGridViewTextBoxColumn.Name = "Latitude"
Me.LongitudeDataGridViewTextBoxColumn.Name = "Longitude"
Me.IdLOMADataGridViewTextBoxColumn.Visible = False
Me.DiskNumDataGridViewTextBoxColumn.Visible = False
Me.DataGridViewTextBoxColumn1.Visible = False
Me.InsertDteDataGridViewTextBoxColumn.Visible = False
Me.LOMAStatusDataGridViewTextBoxColumn.Visible = False
Me.NotesDataGridViewTextBoxColumn.Visible = False
Me.StateDataGridViewTextBoxColumn.Visible = False
Me.SupercedeDataGridViewCheckBoxColumn.Visible = False
Me.UpdatedDteDataGridViewTextBoxColumn.Visible = False
End With
Me.dgDE.Visible = True
Me.dgDE.Rows(0).Selected = True
Me.dgDE.BringToFront()
If Me.dgDE.Rows(0).Cells("LOMAStatusDataGridViewTextBoxColumn").Value.ToString = "2" Then
MessageBox.Show("Warning: this case number has been previously inserted.")
End If
Catch ex As Exception
MessageBox.Show("Error setting data entry bindings: " & ex.Message.ToString)
End Try
End Sub
My questions:
Should I create my app.config file from scratch?
If I need to change a server environment, can I just change the app.config file (and call
Configuration.ConfigurationManager
instead ofMy.Settings...
)?If I change the app.config file, how would I re-bind my data sources without opening the solution, re-creating the data sources, and cleaning/re-building? (Because currently, I connect to the new
data source
, drag the binding sources onto my control, and update the dataset code manually)
I have looked here:
How To Change The Connection String saved in My.Settings in VB 2010
https://msdn.microsoft.com/en-us/library/ms171889(v=vs.90).aspx
But, like I said, I'm not sure if I'm searching for the right answer.