Hi im trying to insert date to my .mdb database, but when i check it, the date turned into random numbers, like 3.2938482

here's my code

Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dbperpus.mdb"
        Dim query2 As String = "select * from fpinjam2"
        connect = New OleDbConnection(constring)

        connect.Open()
        cmd = New OleDbCommand(query2, connect)
        datar = cmd.ExecuteReader
        datar.Read()

        Dim insert As String = "insert into fpinjam2 values('" & nimtxt.Text & " ','" & namatxt.Text & "','" & kodetxt.Text & "','" & judultxt.Text & "','" & tanggalpinjam.Text & "'," & tanggalbaliktxt.Text & ")"
        cmd = New OleDbCommand(insert, connect)
        cmd.ExecuteNonQuery()
        MessageBox.Show("insert successful")
        connect.Close()
        datas.Clear()
        mainconnect()

    End Sub

image: http://i.imgur.com/yfdyO.png

thanks :)

Edited 4 Years Ago by mantapgan: n/a

See this "tanggalpinjam.Text and tanggalbaliktxt.Text"
I think this the problem. You want to insert a date of borrowed date n returning date but you insert it as text.
Just convert it to date format. Make sure the type of both column is date in your database not text or numeric.

did you already convert it to date format?

FormatDateTime(tanggalbaliktxt.Text, DateFormat.ShortDate)

its like this right?

Dim insert As String = "insert into fpinjam2 values('" & nimtxt.Text & " ','" & namatxt.Text & "','" & kodetxt.Text & "','" & judultxt.Text & "','" & FormatDateTime(tanggalpinjam.Text, DateFormat.ShortDate) & "'," & FormatDateTime(tanggalbaliktxt.Text, DateFormat.ShortDate) & ")"

still not working

Edited 4 Years Ago by mantapgan: n/a

ahh..its solved now, its should be like this

Dim insert As String = "insert into fpinjam2 values('" & nimtxt.Text & " ','" & namatxt.Text & "','" & kodetxt.Text & "','" & judultxt.Text & "','" & tanggalpinjam.Text & "','" & tanggalbaliktxt.Text & "')"

instead of

Dim insert As String = "insert into fpinjam2 values('" & nimtxt.Text & " ','" & namatxt.Text & "','" & kodetxt.Text & "','" & judultxt.Text & "','" & tanggalpinjam.Text & "'," & tanggalbaliktxt.Text & ")"
This question has already been answered. Start a new discussion instead.