110,539
社区成员
发帖
与我相关
我的任务
分享
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
string names = Convert.ToString(this.dataGridView1.CurrentRow.Cells[0].Value.ToString());//你这样写也没错
BSXX bx = new BSXX();
bx.name=names;
bx.ShowDialog();
}
public string name { get; set; }
private void GetData(string selectCommand)
{
try
{
string connStr = "server=123.234.29.22,11111;database=TZYDB;uid=sa;pwd=aronwang;max pool size=32767";
SqlConnection Co = new SqlConnection(connStr);
// Create a new data adapter based on the specified query.
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCommand, Co);
// Create a command builder to generate SQL update, insert, and
// delete commands based on selectCommand. These are used to
// update the database.
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
// Resize the DataGridView columns to fit the newly loaded content.
dataGridView1.AutoResizeColumns(
DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
catch (SqlException)
{
MessageBox.Show("To run this example, replace the value of the " +
"connectionString variable with a connection string that is " +
"valid for your system.");
}
}
private void BSXX_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = bindingSource1;
GetData("select * from cx where 售点名称 ='"+name+"'");
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
string names = Convert.ToString(this.dataGridView1.CurrentRow.Cells[0].Value.ToString());
BSXX bx = new BSXX(names);
bx.ShowDialog();
}
子窗体
public string name { get; set; }
public BSXX(string names)
{
InitializeComponent();
name = names;
}
private void GetData(string selectCommand)
{
try
{
string connStr = "server=123.234.29.22,11111;database=TZYDB;uid=sa;pwd=aronwang;max pool size=32767";
SqlConnection Co = new SqlConnection(connStr);
// Create a new data adapter based on the specified query.
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCommand, Co);
// Create a command builder to generate SQL update, insert, and
// delete commands based on selectCommand. These are used to
// update the database.
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
// Resize the DataGridView columns to fit the newly loaded content.
dataGridView1.AutoResizeColumns(
DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
catch (SqlException)
{
MessageBox.Show("To run this example, replace the value of the " +
"connectionString variable with a connection string that is " +
"valid for your system.");
}
}
private void BSXX_Load(object sender, EventArgs e)
{
string sqlt = name;
dataGridView1.DataSource = bindingSource1;
GetData("select * from cx where 售点名称 = sqlt");
}