Good day,
I have been trying to figure out the source of error in my application. What this function (GetConcentrations()
) is to display data from my database onto a DataGridView. The function is called in the PageLoad but works fine but when I call it in another Sub, I get this error.
Could anyone help me? I already tried different ways.
Thanks!
Here is the code:
Private Sub GetConcentrations()
Dim conString As String = ConfigurationManager.ConnectionStrings("dbAsthmaConnectionString").ConnectionString
Me.dataAdapter = New SqlDataAdapter("Select * from tblConcentrations", conString)
'Dim adapter As New SqlDataAdapter("Select * from tblConcentrations", conString)
Dim dataset As New Data.DataSet
Try
Dim commandBuilder As New SqlCommandBuilder(Me.dataAdapter)
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
Me.dataAdapter.Fill(table)
'Dim datasetgetconcentrations = New DataSet
Me.dataAdapter.Fill(dataset)
Me.bindingSource1.DataSource = table
DataGridView3.AutoResizeColumns(DataGridViewAutoSizeColumnMode.AllCellsExceptHeader)
DataGridView3.DataSource = dataset.Tables(0)
dataset.Dispose()
Catch ex As Exception
MsgBox("Failed to display the concentration table (GetConcentrations)!", MsgBoxStyle.Information)
End Try
'Dim ConcentrationValue As Double = DataGridView2.Rows.Contains
'TextBoxCurrentConcentration.Text = txtMessage.Text
End Sub