0

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 by mantapgan: n/a

2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by mantapgan
0

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.

0

did you already convert it to date format?

FormatDateTime(tanggalbaliktxt.Text, DateFormat.ShortDate)
0

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 by mantapgan: n/a

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.