Solved

ado.net datagrid update timestamp query

Posted on 2004-08-29
2
322 Views
Last Modified: 2012-08-13
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]);
                  Inv=box.Text;

                  // 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();
            
ToDa.ToString();
                  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["@Part_Key"].Value=Key;


                  SCom.Parameters.Add("@Inventory_Status", SqlDbType.Char);
                  SCom.Parameters["@Inventory_Status"].Value=Inv;


                  SCom.Parameters.Add("@Reserve_Time", SqlDbType.DateTime);
                  SCom.Parameters["@Reserve_Time"].Value=ToDa;


                SCom.Parameters["@Part_Key"].Value = DGrid.DataKeys[(int)e.Item.ItemIndex];
            SCom.Connection.Open();
0
Comment
Question by:devlins
2 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 500 total points
Comment Utility
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;
datagrid.databind();

dataTable["Timestamp"] = DateTime.Now.Date.ToUniversalTime();
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now