如何将数据从一个窗体上的 datagridview 控件传递到另一个窗体上的控件?我正在使用以下代码从我的数据库中检索信息 - 然后当用户选择适当的行时,我希望另一个表单上的控件显示与该行对应的数据。这可能吗?如果可以,我该怎么做?
这是我的代码:
If TextBox1.Text = "" Then
MessageBox.Show("You must enter an account number to proceed!")
TextBox1.Focus()
Me.Refresh()
Else
Try
dbConn = New MySqlConnection("Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=123456;Password=234567;Database=accounting")
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
End If
dbConn.Open()
Dim dbAdapter As New MySqlDataAdapter("SELECT ccNumber, ccExpireMonth, ccExpireYear, ccZipcode FROM cc_master WHERE customer_accountNumber = " & TextBox1.Text, dbConn)
Dim myDatatable As New DataTable
dbAdapter.Fill(myDatatable)
If myDatatable.Rows.Count > 0 Then
DataGridView1.DataSource = myDatatable
Else
MessageBox.Show("No Customer Records Found! Please try again!")
TextBox1.Clear()
TextBox1.Focus()
End If
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
End If