none
how to Automatic Adding Current Date and Time in the column datagridview use sql server in vb.net ?

    Question

  • how to Automatic Adding Current Date and Time in the column datagridview use sql server in vb.net ?

    please step by step

    Tuesday, February 26, 2013 6:36 PM

All replies

  • "srajmuneer" wrote in message news:f92e0148-9134-401b-bf09-782e45079f71...

    how to Automatic Adding Current Date and Time in the column datagridview use sql server in vb.net ?

    please step by step

    If you have access to the stored procedure you can "dummy" the current date/time e.g.

    Select     GetDate() as CurrentDate,

                    MyColumn1    etc

    from             MyTable


    Harry
    Tuesday, February 26, 2013 10:08 PM
  • If you are using a SQL stored procedure, add this to your update query:

    update TableName
    	set UpdateDateTime = getdate()
    where UserID = @UserID
     


    Chuck

    Friday, March 01, 2013 10:54 PM
  • Hello,

    The following shows how to set the current date/time (you can set the formatting as needed for the date column in code or via setup in the IDE).

    Form load simply provides some mocked data to demo using the DataGridview event DefaultValueNeeded.

    The date column is set to read-only but does not need to be.

    Private Sub Form1_Load(
        ByVal sender As System.Object,
        ByVal e As System.EventArgs) _
    Handles MyBase.Load
        Dim dt As New DataTable
        dt.Columns.AddRange(New DataColumn() _
            {
                New DataColumn With
                {
                    .ColumnName = "ID",
                    .DataType = GetType(Int32),
                    .AutoIncrement = True,
                    .ReadOnly = True
                },
                New DataColumn With
                {
                    .ColumnName = "Item",
                    .DataType = GetType(String)
                },
                New DataColumn With
                {
                    .ColumnName = "SaleDate",
                    .DataType = GetType(Date),
                    .ReadOnly = True
                }
            }
        )
        dt.Rows.Add(New Object() {Nothing, "AAAA", #1/1/2013 12:00:00 PM#})
        dt.Rows.Add(New Object() {Nothing, "BBBB", #1/11/2013 2:03:01 PM#})
        dt.Rows.Add(New Object() {Nothing, "CCC", #3/4/2013 9:33:00 AM#})
        DataGridView1.DataSource = dt
    End Sub
    Private Sub DataGridView1_DefaultValuesNeeded(
        ByVal sender As Object,
        ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) _
    Handles DataGridView1.DefaultValuesNeeded
        e.Row.Cells("SaleDate").Value = Now
    End Sub


    kevininstructor

    Saturday, March 02, 2013 4:18 AM
    Moderator
  • Hey srajmuneer,

    Did you get your question answered???


    Chuck

    Tuesday, March 05, 2013 6:23 PM