当我将值从调用表单传递给弹出窗口时,会收到值,但是当代码到达while(drInsiderInfo.Read)语句时,它会弹回到调用表单上的insiderPopUp.ShowDialog,而DataReader从不执行。
这是我的CellClick事件代码:
private void allInsiderTransactionsDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
string passedInsider;
try
{
passedInsider = allInsiderTransactionsDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString();
DataGridViewCell cellClicked = (DataGridViewCell)allInsiderTransactionsDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (cellClicked.ColumnIndex == this.allInsiderTransactionsDataGridView.Columns["Insider"].Index)
{
frmInsiderPopUp insiderPopUp = new frmInsiderPopUp(passedInsider);
insiderPopUp.passedNumber = passedInsider;
insiderPopUp.ShowDialog();
}
}
catch (Exception ex)
{
throw (ex);
}
}
这是我的弹出窗体DataReader代码:
public string passedNumber { get; set; }
public frmInsiderPopUp(string passedNumber)
{
InitializeComponent();
passedInsiderNumberTextBox.Text = passedNumber;
populateVipNumberTextBoxes();
}
public void populateVipNumberTextBoxes()
{
if (passedInsiderNumberTextBox.Text != null)
connect.Open();
try
{
SqlCommand insiderStProc = new SqlCommand("RMM3InsiderInformation");
insiderStProc.Connection = connect;
insiderStProc.CommandType = CommandType.StoredProcedure;
insiderStProc.Parameters.AddWithValue("@InsiderNumber", passedInsiderNumberTextBox.Text);
using (SqlDataReader drInsiderInfo = insiderStProc.ExecuteReader())
{
while (drInsiderInfo.Read())
{
insiderNameTextBox.Text = drInsiderInfo["Name"].ToString();
insiderStoreTextBox.Text = drInsiderInfo["Store"].ToString();
insiderPhoneTextBox.Text = drInsiderInfo["Phone"].ToString();
insiderStreetTextBox.Text = drInsiderInfo["Street"].ToString();
insiderSuiteTextBox.Text = drInsiderInfo["Apt"].ToString();
insiderCityTextBox.Text = drInsiderInfo["City"].ToString();
insiderStateTextBox.Text = drInsiderInfo["State"].ToString();
insiderZipCodeMaskedTextBox.Text = drInsiderInfo["ZipCode"].ToString();
insiderEmailTextBox.Text = drInsiderInfo["Email"].ToString();
insiderSignUpDateMaskedTextBox.Text = drInsiderInfo["DateIn"].ToString();
insiderLastMailedMaskedTextBox.Text = drInsiderInfo["LastMailed"].ToString();
insiderTotalTransactionsTextBox.Text = drInsiderInfo["TotalTrans"].ToString();
insiderTotalDollarsTextBox.Text = drInsiderInfo["TotalDollars"].ToString();
insiderColorTextBox.Text = drInsiderInfo["Color"].ToString();
}
}
}
catch (Exception ex)
{
throw (ex);
}
connect.Close();
}