Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

databinding datetimepicker

$
0
0

I am having trouble binding a datetimepicker to a bindingsource.

Everything works fine until I save or update a record then all the binding to the bindingsource stop working;

empBindingSource.DataSource = dataSet1.Tables["employees"];

Binding b = new Binding("Value", empBindingSource, "Medical_Date");
            b.DataSourceNullValue = DateTime.Now;
            medicaldateTimePicker.DataBindings.Add(b);

                                            

private void emp_new_btn_Click(object sender, EventArgs e)
        {
            if (emp_new_btn.Text == "New")
            {
                emp_new_btn.Text = "Cancel";
                emp_new_btn.ForeColor = Color.Red;
                empBindingSource.AddNew();

                dataGridView1.Enabled = false;
                emp_del_btn.Enabled = false;

            }
            else
            {
                empBindingSource.RemoveCurrent();
                emp_new_btn.Text = "New";
                emp_new_btn.ForeColor = Color.Black;
                dataGridView1.Enabled = true;
                emp_del_btn.Enabled = false;
            }

        }

            

private void emp_save_btn_Click(object sender, EventArgs e)
        {
            dataGridView1.Enabled = true;
            this.Validate();
            this.empBindingSource.EndEdit();
            SqlCommandBuilder cb = new SqlCommandBuilder(emp_da);
            if (emp_new_btn.Text == "Cancel")
            {
                cb.DataAdapter.Update(dataSet1.Tables["employees"]);
                DB_Handler create = new DB_Handler();
                create.create_ps_tbl(idNumtextbox.Text);
                emp_new_btn.Text = "New";
                emp_new_btn.ForeColor = Color.Black;
                emp_del_btn.Enabled = true;
            }

            else
            {
                cb.DataAdapter.Update(dataSet1.Tables["employees"]);
                upd_emp_tbl();
                upd_emp_tv();
            }
            upd_emp_tbl();
            upd_emp_tv();

        }

Will appreciate some help with this.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>