I have a program with two forms, form1 ans form2. Form1 displays a data grid view (EX1) from a SQL table. Form2 allows you to modify the search criteria in the data grid. This is accomplished by pressing a button on form2 but showing the results on form1(EX2).
This is the code in form1:
Call dgv() generates a error: BC30369 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
What am I doing wrong?
EX1 (code in form1):
EX2 (code in form2):
This is the code in form1:
Code:
Public Shared Sub testsub()
MsgBox("Hello")
Call dgv() '<<<<<<< Generates an error
End Sub
What am I doing wrong?
EX1 (code in form1):
Code:
Public Sub dgv()
' Dim dgv_rec As New DataGridView
Dim qry As String = "select recd_id, recd_number, recd_inventorydate from t021400_records order by recd_number desc;"
Dim cs As String = gs_SQL_CS_RecordManagement
Try
Dim connectionString As String = cs
Dim connection As New SqlConnection(connectionString)
Dim dataadapter As New SqlDataAdapter(qry, connection)
Dim ds As New DataSet()
connection.Open()
dataadapter.Fill(ds, "dgv")
' dataadapter.Fill(ds)
connection.Close()
dgv_Records.DataSource = DBNull.Value
dgv_Records.DataSource = ds
dgv_Records.DataMember = "dgv"
With dgv_Records
.RowsDefaultCellStyle.BackColor = Color.Bisque
.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige
End With
Catch EX As Exception
MsgBox(EX.ToString & " - (SQLRoutines-ReadT010200_MyManagementTeam)")
Exit Sub
End Try
End Sub
EX2 (code in form2):
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form1.testsub()
End Sub
End Class
Comment