Hi, i had trired your method. But i think the logic of my codes have something incorrect. Could anyone help me with it? I will be using controller and a presentation layer.
'This is the method where i get from the table and select the datetime to compare with another datetime. This codes will be place in the controller.
Public Function selectDateTime(ByVal subCat1 As String)
Dim a As String
Dim cmd As New SqlCommand
cn.Open()
cmd.CommandText = "SELECT datTim FROM msg WHERE subCat = '" + subCat1 + "'"
cmd.Connection = cn
a = cmd.ExecuteScalar()
cn.Close()
End Function
'This is the code where i place it in the presentation layer. Where n is equal to string and dl is to link with the controller class. strSubcat is the label.text
n = dl.selectDateTime(strSubcat)
'this is the method to insert into the db while select the time from db and compare with the now datetime.
Public Function insertNewMessage(ByVal strmsg As String, ByVal datTim As DateTime, ByVal userID As String, ByVal status As String) As DataSet
Dim d As String
Dim subCat1 As String
Dim t As DateTime = DateTime.Now
Dim t4 As DateTime = selectDateTime(subCat1)
cn.Open()
If DateTime.Compare(t, t4) Then
Dim query As String = "INSERT INTO msg(msg, datTim,userID, status) VALUES ('" & strmsg & "', '" & t & "','" & "s693" & "','" & "first" & "')"
Dim myAdapter As New SqlDataAdapter(query, cn)
myAdapter.Fill(ds, "h")
cn.Close()
Return ds
ElseIf DateTime.Compare(t, t4) > 0 Then
Dim query As String = "INSERT INTO msg(msg, datTim,userID, status) VALUES ('" & strmsg & "', '" & t & "','" & "s693" & "','" & "reply" & "')"
Dim myAdapter As New SqlDataAdapter(query, cn)
myAdapter.Fill(ds, "h")
cn.Close()
Return ds
End If
End Function
It able to insert teh now datetime and the message into the table. But it can't compare the datetime and insert the status to first or reply. Can anybody help me with this? Thankx.
Tiffany