如何将类中的结果发送到其他类,结果来自我的mysql结果。 例如,第一类是databaseConnection,我想将select方法的结果发送到其他类。
这是我的代码:
Dim data As ArrayList
Public Function selectAll() As ArrayList
Dim mySelectQuery As String = "SELECT * FROM users"
Dim myConnection As New MySqlConnection(connectionString)
Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As MySqlDataReader
myReader = myCommand.ExecuteReader()
' Always call Read before accessing data.
data = myReader
' always call Close when done reading.
myReader.Close()
' Close the connection when done with it.
myConnection.Close()
End Function
我更新了一个代码,看起来更清晰 和接收器方法看起来像这样。
Private Sub home_Load(sender As Object, e As EventArgs) Handles MyBase.Load
db = New db()
Dim r = db.selectAll()
MsgBox("It work" & db.selectAll().ToString())
End Sub
答案 0 :(得分:2)
你可以做很多种方式。
但是,我可能会将结果输出到第一个函数中的变量。然后只需根据需要从第二个访问变量。
示例:
在第一种方法中:
Dim list As New List(Of String)
While myReader.Read()
list.add(myreader.GetString(0))
End While
第二
Dim listTransfer as list(Of String)
Foreach ele as String in classname.list ' Replace classname '
listTransfer.add(ele)
Next