I have a button on a form. The form also contains 8 text boxes. Once the text boxes have been filled out; the button is selected to save the data in a datatable called SetUpTable.
If the button is pressed again to prevent a error occurring, I have put in an
If statement to check and see if the datatable contains a row. (There should only be 1 row maximum) However the code I am using reads 0 rows irrespective of whether the datatable is new with no rows or already has 1 row. So what am I doing wrong?
In debug mode, I can see that the datatable contains one row when I press the button the second time but the expression
SetupTable.Rows.Count
states the row count to be 0.
What I have tried:
Public SetupTable As DataTable = New DataTable()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Title As String = "SetUp"
Dim rowws As Integer
rowws = SetupTable.Rows.Count
If SetupTable.Rows.Count > 0 Then
SetupTable.Rows(0).Item(0) = WFileDir.Text
SetupTable.Rows(0).Item(1) = YBFileDir.Text
SetupTable.Rows(0).Item(2) = MFileDir.Text
SetupTable.Rows(0).Item(3) = Port.Text
SetupTable.Rows(0).Item(4) = Cred.Text
SetupTable.Rows(0).Item(5) = Host.Text
SetupTable.Rows(0).Item(6) = EmailFrom.Text
SetupTable.Rows(0).Item(7) = EmailTo.Text
Else
SetupTable.Columns.AddRange(New DataColumn() {
New DataColumn(WFileDir.Text, GetType(String)),
New DataColumn(YBFileDir.Text, GetType(String)),
New DataColumn(MFileDir.Text, GetType(String)),
New DataColumn(Port.Text, GetType(String)),
New DataColumn(Cred.Text, GetType(String)),
New DataColumn(Host.Text, GetType(String)),
New DataColumn(EmailFrom.Text, GetType(String)),
New DataColumn(EmailTo.Text, GetType(String))})
End If