Code Sample for Datasets and DataGridViews

        public Form1()
            SqlConnection cnt = new SqlConnection(GetConnectionString());

            SqlCommand cmd = cnt.CreateCommand();
            cmd.CommandText = “select * from Orders; select * from [Order Details]”;
            northwind.Load( cmd.ExecuteReader(), LoadOption.OverwriteChanges, “Orders”,”Order Details”);

        static private string GetConnectionString()
            // To avoid storing the connection string in your code,
            // you can retrieve it from a configuration file, using the
            // System.Configuration.ConfigurationSettings.AppSettings property
            return “Data Source=(local);Initial Catalog=Northwind;”
                + “Integrated Security=SSPI;”;

        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
            string s = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
            orderDetailsBindingSource.Filter = “OrderId=” + s;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s