inserting today's date - date only

akhanmac

New member
Joined
Jun 19, 2007
Messages
3
Programming Experience
Beginner
below code updates a table if changes are made. I need to add today's date, not time, to the table.
the field in the table is created, and i dont want to pass the date to this function, just want to pull the date from with in here.

n e help would be great.

the new field is lastUpdateDate and the value can be assigned to lastUpdateDate

thanks




Public Sub UpdateLot(ByVal lotuk As Integer, _
ByVal condcode As String, ByVal expdate As String, _
ByVal shelflifecodeI As String, ByVal shelflifecodeII As String, ByVal remarks As String)
'gn these converts are only necessary because the engine doesn't
'support nulls and treats empty strings in the controls as nulls - so convert back to empty string!

Dim nulldate As SqlDateTime
nulldate = SqlDateTime.Null




'determine imagename based on
Dim imagename As String = SetImageName(expdate, shelflifecodeI, shelflifecodeII)


'Updates the lot table
Dim sql As String = "UPDATE lotno SET condcode = " & _
" @condcode, expdate= @expdate, shelflifecodeI = " & _
"@shelflifecodeI, shelflifecodeII = @shelflifecodeII, " & _
" imagename = @imagename, remarks = @remarks " & _
" WHERE lotuk = @lotuk"


Try
m_Command.CommandText = sql
m_Command.Parameters.Add(New SqlParameter("@condcode", common.FormatStrForDB(condcode)))

If expdate = Nothing Then
'setting null for query
m_Command.Parameters.Add(New SqlParameter("@expdate", nulldate))
Else
m_Command.Parameters.Add(New SqlParameter("@expdate", expdate))
End If

m_Command.Parameters.Add(New SqlParameter("@shelflifecodeI", common.FormatStrForDB(shelflifecodeI)))
m_Command.Parameters.Add(New SqlParameter("@shelflifecodeII", common.FormatStrForDB(shelflifecodeII)))
m_Command.Parameters.Add(New SqlParameter("@imagename", imagename))
'don't want to convert to upper - for readability
If remarks = Nothing Then
remarks = ""
End If
m_Command.Parameters.Add(New SqlParameter("@remarks", remarks))
m_Command.Parameters.Add(New SqlParameter("@lotuk", lotuk))

m_Command.ExecuteNonQuery()

Catch excpSQL As System.Data.SqlClient.SqlException
If m_blnConnectedTransaction Then
m_blnExecuteOK = False
m_TransMain.Rollback()
End If
Throw New Exception(excpSQL.ToString())

Catch excpSystem As System.Exception
If m_blnConnectedTransaction Then
m_blnExecuteOK = False
m_TransMain.Rollback()
End If
Throw New Exception(excpSystem.ToString())

Finally
m_Command.Parameters.Clear()

End Try

End Sub
 
You could always play around with the generic Date object provided. This has all the properties like Day, Month, Year and you could just build a string that would be pretty much the same thing if you absolutely did not want the time included from some reason.
 
Back
Top