Code Sample for Datasets and DataGridViews

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

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

        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:

WordPress.com Logo

You are commenting using your WordPress.com 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