Hello sir,
I have an application in which on button click there will be pop up window and on that window i have to show data from database in tabular format So. how i can do this

Recommended Answers

All 2 Replies

Create a new form for your pop-up window. Put a DataGridView on it. Bind the query to the DataGridView. Done.

Tabular? Whats is this? Does the dataGridView control satisify your expectations?
So, back to your issue.
Get wanted values from database( use DataTable to fill it up), then open Form2 (new pop-up window) and pass dataTable parameter to it (it can be passed in the constructor of form2). Then bind dataGridView with dataTable (use dataSource). And here you go . data from database are in pop-up window.

//in rough:

//On form1:
        private void OpenPopUp()
            DataTable table = GetData();
            if (table.Rows.Count > 0)
                Form2 f2 = new Form2(table);

        private DataTable GetData()
            using (SqlConnection sqlConn = new SqlConnection("ConnectionString"))
                string query = "SELECT a, b, c FROM MyTable";
                SqlDataAdapter da = new SqlDataAdapter(query, sqlConn);
                DataTable table = new DataTable("myTable");
                da.SelectCommand.Connection = sqlConn;
                return table;

//on form2 (pop-up):
    public partial class Form2 : Form
        public Form2 (DataTable table)
            DataGridView dgv = new DataGridView();
            dgv.Location = new Point(10, 10);
            dgv.AllowUserToAddRows = false;
            dgv.RowHeadersVisible = false;
            dgv.ReadOnly = true;
            dgv.DataSource = new BindingSource(table, null);

If this is no clear enough, let me know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.