Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i make date and time display in phpmyadmin as correct date and time not in 00:00:00 and 0000-00-00? i using vb.net for this project
Posted
Updated 15-Jul-14 21:45pm
v2
Comments
nilesh sawardekar 16-Jul-14 4:54am    
please explain in brief or code that your using for this.
Member 10896203 16-Jul-14 5:12am    
this my coding..

Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Globalization

Public Class Form1
Dim con As New MySqlConnection
Dim cmd As New MySqlCommand
Dim result As Integer

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub

Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
con.ConnectionString = "server=localhost;user id=root;password=123456;database=activity log"

Try

con.Open()

With cmd
.Connection = con
.CommandText = "INSERT INTO `activity log`.`details`(`id`, `Username`, `Description`, `Time`, `Date`) VALUES (NULL,'" & txtUsername.Text & "','" & txtDesc.Text & "','" & TextBox1.SelectedText & "', '" & TextBox2.SelectedText & "');"

result = cmd.ExecuteNonQuery

If result = 0 Then
MsgBox("Data has been inserted")
Else
MsgBox("Successfully saved")
End If
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
End Sub
'create time follow to current time and for record log
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.Text = (Format(Now, "HH:mm:ss"))
End Sub
'create date for record log
Private Sub TextBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.Click
TextBox2.Text = DateString
End Sub

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
con.ConnectionString = "server=localhost;user id=root;password=123456;database=activity log"

Try
con.Open()

With cmd
.Connection = con
.CommandText = "SELECT * FROM details"

End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
ListDetails()
End Sub

Public Sub ListDetails()

Dim dr As MySqlDataReader
con.Open()
dr = cmd.ExecuteReader()
ListView1.Items.Clear()
'Dim
While dr.Read()
Dim new_item As New _
ListViewItem(dr.Item("id").ToString)
new_item.SubItems.Add(dr.Item("Username").ToString)
new_item.SubItems.Add(dr.Item("Description").ToString)
new_item.SubItems.Add(dr.Item("Time").ToString)
new_item.SubItems.Add(dr.Item("Date").ToString)

ListView1.Items.Add(new_item)
End While
con.Close()
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
ListView1.Items.Clear()
txtUsername.Clear()
txtDesc.Clear()
End Sub
End Class
Member 10896203 16-Jul-14 5:18am    
i got error it say An unhandled exception of type 'MySql.Data.Types.MySqlConversionException' occurred in MySql.Data.dll in line ' new_item.SubItems.Add(dr.Item("Date").ToString)' after i delete that line and check my database time and date still 0000-00-00 n 00:00:00.

i get problem to save correct date and time in database..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900