Link to home
Start Free TrialLog in
Avatar of holemania
holemania

asked on

VB.Net DataGridView - Update

I have a windows form that I added a datagridview.  I am able to make update to one of the column that I had allowed users to make update.  However, when the cell for that particular row  is updated, I want it to update the "Modified_date" column with current date/time.

Anyone know how this can be done?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of holemania
holemania

ASKER

Thanks.  I will take a look and see how I can incorporate that with my current code.

Dim myDA As SqlDataAdapter
Dim myDT as DataTable 

Sub Query()
	Dim con As SqlConnection = New SqlConnection("Data Source=SVR;persist security info=False;initial catalog=SANDDB1;UID=SandBoxUser;PWD=SandDB01;")
        Dim cmd As SqlCommand = New SqlCommand("SELECT DISTINCT TRANS_ID, ITEM_ID, COMPLETE, MODIFIED_DATE FROM ITEM_DETAIL ", con)

        con.Open()

        myDA = New SqlDataAdapter(cmd)

        Dim builder As New SqlCommandBuilder(myDA)
        myDA.UpdateCommand = builder.GetUpdateCommand()

        myDT = New DataTable()

        myDA.Fill(myDT)



        'ALTERNATE COLOR
        Me.dgLookup.RowsDefaultCellStyle.BackColor = Color.White
        Me.dgLookup.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray


        dgLookup.DataSource = myDT

        'COLUMN
        Me.dgLookUP.Columns("TRANS_ID").Visible = False
        Me.dgLookUP.Columns("ITEM_ID").Width = 100
        Me.dgLookUP.Columns("COMPLETE").Width = 150
        Me.dgLookUP.Columns("MODIFIED_DATE").Width = 50
  

        Try
           If dgLookUP.Rows.Count = 0 Then
              con.Close()
              con = Nothing
              Exit Sub

              End If

           Catch ex As Exception
              MsgBox(ex.Message)
           End Try


         con.Close()
         con = Nothing
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
       Try
	  myDA.Update(myDT)
       Catch
          MsgBox(ex.Message)
       End Try
End Sub

Open in new window


I am basically allowing person to update the "Complete" cells and then automatically update the Modified_date column with today's date.
Thank  you.