mardi 21 avril 2015

C# update then delete record in datagridview

In my project I need to update the attn_dateTimeOut in database. After I updated it will automatic delete the specific row record that had been updated. I had two question:

1) In my database there are a few table is assign not null."attn_dateTimeOut" is a table that haven insert any record. When I update it using below code,it work and can update but it comes out error. Error show "record cannot be null".

2) I want to make it when I updated the "attn_dateTimeOut", it will auto delete the row of updated record. I do using back code "DeleteRecord" but it nothing change! How should I do?

Here is my code:

private void txt_proximity_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)13)
    {
        TMPB_attn row_TMPN_attn = BusinessLogicLayer.TMS_GET_PROXIMITY_VALID_TO_USE(txt_proximity.Text);
        if (!String.IsNullOrEmpty(txt_proximity.Text))
        {
            using (TMPB_attn_DAL dalObj = new TMPB_attn_DAL())
            {
                if (row_TMPN_attn != null)
                {
                    try
                    {
                        row_TMPN_attn.attn_dateTimeOut = Convert.ToDateTime(DateTime.Now);
                        dalObj.UpdateRecord(row_TMPN_attn);
                        dalObj.DeleteRecord();
                        MessageBox.Show("Update Successful");
                        txt_proximity.Text = "";
                        loadGridView();
                    }
                    catch (Exception es)
                    {
                        MessageBox.Show(es.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Proximity No. is not exist");
                    txt_proximity.Text = "";
                }
            }
        }
        else
        {
            MessageBox.Show("Please try again");
            txt_proximity.Text = "";
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire