• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

ado.net datagrid update timestamp query

Say I have some code like below. How would I be able to get focus of the current update row and input a timestamp within a column without making the current row's date column editable but input a current timestamp automatically?

string Inv, dateT;
string Key = DGrid.DataKeys[e.Item.ItemIndex].ToString();
TextBox box;
                  box = (TextBox)(e.Item.Cells[1].Controls[0]);

                  // Gets the value the TextBox control in the fourth column
                  box = (TextBox)(e.Item.Cells[8].Controls[0]);
                  dateT= box.Text;

                  string Sq;
                  DateTime ToDa = DateTime.Now.Date.ToUniversalTime();
                  Sq = "Update [Waveplate]" +
                        "set Inventory_Status=@Inventory_Status, Reserve_Timestamp = "+ToDa+
                        "where Part_Key =@Part_Key";

                  SqlCommand SCom = new SqlCommand(Sq, Conn);
                  //SqlParameterCollection CSql = SCom.Parameters;

                  SCom.Parameters.Add("@Part_Key", SqlDbType.Char);

                  SCom.Parameters.Add("@Inventory_Status", SqlDbType.Char);

                  SCom.Parameters.Add("@Reserve_Time", SqlDbType.DateTime);

                SCom.Parameters["@Part_Key"].Value = DGrid.DataKeys[(int)e.Item.ItemIndex];
1 Solution
If u databind a datagrid to a datasource (Eq:a datatable) then if u update the value of the Timestamp column in the datatable then automatically the datagrid should be refreshed with the new data

datagrid.datasource = dataTable;

dataTable["Timestamp"] = DateTime.Now.Date.ToUniversalTime();
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now