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 :)

Recommended Answers

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.

Jump to Post

did you already convert it to date format?

FormatDateTime(tanggalbaliktxt.Text, DateFormat.ShortDate)
Jump to Post

All 5 Replies

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

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 & ")"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.