SQL
Private Declare Function NetRemoteTOD Lib _
[Ô]NETAPI32.DLL[Ô] (ByVal server As _
String, buffer As Any) As Long
Private Declare Sub CopyMemory Lib [Ô]kernel32[Ô] _
Alias [Ô]RtlMoveMemory[Ô] (hpvDest As _
Any, hpvSource As Any, ByVal cbCopy _
As Long)
Private Declare Function NetApiBufferFree Lib _
[Ô]NETAPI32.DLL[Ô] (buffer As Any) As Long
Private Type TIME_OF_DAY
t_elapsedt As Long
t_msecs As Long
t_hours As Long
t_mins As Long
t_secs As Long
t_hunds As Long
t_timezone As Long
t_tinterval As Long
t_day As Long
t_month As Long
t_year As Long
t_weekday As Long
End Type
Public Function ServerTime(ByVal pServerName _
As String) As Variant
Dim t As TIME_OF_DAY
Dim tPtr As Long
Dim Result As Long
Dim szServer As String
Dim ServDate As Date
If Left(pServerName, 2) = [Ô]\[Ô] Then
szServer = StrConv(pServerName, vbUnicode)
Else
szServer = StrConv([Ô]\[Ô] & pServerName, _
vbUnicode)
End If
Result = NetRemoteTOD(szServer, tPtr)
If Result = 0 Then
Call CopyMemory(t, ByVal tPtr, Len(t))
ServDate = DateSerial(70, 1, 1) + _
(t.t_elapsedt / 60 / 60 / 24)
ServDate = ServDate - (t.t_timezone / 60 / 24)
NetApiBufferFree (tPtr)
ServerTime = ServDate
Else
MsgBox [Ô]Número do Erro : [Ô] & Err.Number & vbCrLf & vbCrLf & [Ô]Descrição : [Ô] & Err.Description
Err.Clear
End If
End Function
[ô]--------------------------------------------------------------------------
[ô]No form
Private Sub Form_Load()
Data = ServerTime([Ô]\NomeDoServidor[Ô])
MsgBox Data
End Sub
Testa ai qualquer coisa posta ai para a gente te ajudar
Se te ajudei encerre o tópico e me pontue, senão posta sua dúvida para te ajudarmos
Citação::
[ô]Num module
Private Declare Function NetRemoteTOD Lib _
[Ô]NETAPI32.DLL[Ô] (ByVal server As _
String, buffer As Any) As Long
Private Declare Sub CopyMemory Lib [Ô]kernel32[Ô] _
Alias [Ô]RtlMoveMemory[Ô] (hpvDest As _
Any, hpvSource As Any, ByVal cbCopy _
As Long)
Private Declare Function NetApiBufferFree Lib _
[Ô]NETAPI32.DLL[Ô] (buffer As Any) As Long
Private Type TIME_OF_DAY
t_elapsedt As Long
t_msecs As Long
t_hours As Long
t_mins As Long
t_secs As Long
t_hunds As Long
t_timezone As Long
t_tinterval As Long
t_day As Long
t_month As Long
t_year As Long
t_weekday As Long
End Type
Public Function ServerTime(ByVal pServerName _
As String) As Variant
Dim t As TIME_OF_DAY
Dim tPtr As Long
Dim Result As Long
Dim szServer As String
Dim ServDate As Date
If Left(pServerName, 2) = [Ô][Ô] Then
szServer = StrConv(pServerName, vbUnicode)
Else
szServer = StrConv([Ô][Ô] & pServerName, _
vbUnicode)
End If
Result = NetRemoteTOD(szServer, tPtr)
If Result = 0 Then
Call CopyMemory(t, ByVal tPtr, Len(t))
ServDate = DateSerial(70, 1, 1) + _
(t.t_elapsedt / 60 / 60 / 24)
ServDate = ServDate - (t.t_timezone / 60 / 24)
NetApiBufferFree (tPtr)
ServerTime = ServDate
Else
MsgBox [Ô]Número do Erro : [Ô] & Err.Number & vbCrLf & vbCrLf & [Ô]Descrição : [Ô] & Err.Description
Err.Clear
End If
End Function
[ô]--------------------------------------------------------------------------
[ô]No form
Private Sub Form_Load()
Data = ServerTime([Ô]NomeDoServidor[Ô])
MsgBox Data
End Sub
Testa ai qualquer coisa posta ai para a gente te ajudar
Se te ajudei encerre o tópico e me pontue, senão posta sua dúvida para te ajudarmos
Não sei pq as pessoas postam os códigos sem analisar o problema...
Veja um exemplos:
Firebird:
CREATE OR ALTER TRIGGER TBL_SUA_TABELA_BI FOR TBL_SUA_TABELA
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
NEW.dta_inclusao=CURRENT_TIMESTAMP;
END
Access: não permite Triggers, mas vc pode colocar como o valor Default do campo na tabela: Now();
No sqlserver:
CREATE TRIGGER TBL_SUA_TABELA_BI
ON TBL_SUA_TABELA BEFORE INSERT
as
BEGIN
-- Gravar data_hora atuais
SET NEW.dta_incluxao = NOW();
END;
Fazendo assim , o prório SGBD se encarrega de gravar o dado, não sendo necessário fazer nenhum tratamento no seu código.
CREATE TRIGGER tg_SUA_TABELA_bi BEFORE INSERT ON TBL_SUA_TABELA
FOR EACH ROW BEGIN
set new.data_inclusao=Now();
END
|
DELIMITER ;