1

我想我需要在此按钮单击事件中编写代码以获得所需的输出,但无法写下步骤。你们的任何帮助都会有所帮助,并使我学习。谢谢你。

 private void btnViewAllEntries_Click(object sender, EventArgs e)

    {
        SqlConnection con = new SqlConnection(Helper.ConnectionString);
        SqlCommand cmd = new SqlCommand("Select * from DirDetails");
        con.Open();


        con.Close();
        MessageBox.Show(DetailsView.cs);//DetailsView.cs is winform with gridview
    }
4

1 回答 1

1

首先,MessageBox只显示messages,而不是Forms。要显示表单,您应该实例化它并使用ShoworShowDialog方法。

DetailsView frm=new DetailsView();
frm.ShowDialog();

二、在查询中运行DetailsView.cs

private void Form1_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(Helper.ConnectionString);
        SqlDataAdapter da = new SqlDataAdapter("Select * from DirDetails", con);
        DataTable dt = new DataTable();
        con.Open();
        da.Fill(dt);
        con.Close();
        datagridview1.DataSource = dt;
    }
于 2012-09-26T13:13:58.640 回答