我填充了我的gridview,我想用gridview 值以及与该记录相关但不在gridview 上的值填充一个表单。我会发布我到目前为止的代码。我知道如何以相同的表单填充文本框,但我需要使用这些值启动一个新表单。
数据层
class DALCustomers
{
DALConnection SBAConnection;
public DALCustomers()
{
SBAConnection = new DALConnection();
}
DataSet GetCustomersDataset = new DataSet();
SqlCommand Customers = new SqlCommand();
Customers.CommandText = "GetCustomers";
Customers.CommandType = CommandType.StoredProcedure;
Customers.Connection = SBAConnection.GetConnection();
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(Customers);
mySqlDataAdapter.Fill(GetCustomersDataset);
return GetCustomersDataset;
}
业务层
class Customer
{
public DataSet GrabCustDataset()
{
DataSet ds = new DataSet();
ds = new DALCustomers().GetCustomers();
return ds;
}
}
界面层
namespace Customer_Database
{
public partial class frmCustomers : Form
{
public frmCustomers()
{
InitializeComponent();
}
private void PopulateCustomerGrid(DataSet CustGrid)
{
dgCustomers.DataSource = null;
dgCustomers.DataSource = CustGrid.Tables[0];
}
private void frmCustomers_Load(object sender, EventArgs e)
{
DataSet ds = new Customer().GrabCustDataset();
PopulateCustomerGrid(ds);
}
private void dgCustomers_DoubleClick(object sender, EventArgs e)
{
frmCustDetails frmCustDetails = new frmCustDetails();
frmCustDetails.Show();
// will fill TB for selected row
//foreach (DataGridViewRow row in dgCustomers.SelectedRows)
//{
// txtTest.Text = row.Cells[2].Value.ToString();
//}
}
}
}