Hello,

can somenone help me solve this problem? i try this code to insert my data into microssoft access 2013 database but when i insert, a new row is created with no data, someone can help me?

this is my code for my save button, only date can insert.

acsconn.Open()
        Dim sqlsearch As String
        sqlsearch = "SELECT Nama, Tajuk FROM RekodPinjam WHERE IC = '" & txtIC.Text & "' AND Kod_Buku = '" & txtKod.Text & "'"
        Dim adapter As New OleDbDataAdapter(sqlsearch, acsconn)
        Dim dt As New DataTable("RekodPinjam")
        adapter.Fill(dt)

        If dt.Rows.Count > 0 Then
            MsgBox("Pelajar telah meminjam buku " & dt.Rows(0).Item(1).ToString)
        ElseIf txtTajuk.Text = "" Then
            MsgBox("Kod Buku tiada dalam rekod!")
        Else
            strsql = "insert into RekodPinjam (Nama, Ic, Kod_Buku, Tajuk, Harga, Tarikh) values (@1, @2, @3, @4, @5, @6)"
            acscmd.CommandText = strsql
            acscmd.Connection = acsconn
            acscmd.Parameters.AddWithValue("@1", txtNama.Text)
            acscmd.Parameters.AddWithValue("@2", txtIC.Text)
            acscmd.Parameters.AddWithValue("@3", txtKod.Text)
            acscmd.Parameters.AddWithValue("@4", txtTajuk.Text)
            acscmd.Parameters.AddWithValue("@5", txtHarga.Text)
            acscmd.Parameters.AddWithValue("@6", DateTimePicker1.Value)
            acscmd.ExecuteNonQuery()
            acscmd.Dispose()
            MsgBox("Peminjaman Berjaya!")
            txtNama.Text = ""
            txtIC.Text = ""
            txtKod.Text = ""
            txtTajuk.Text = ""
            txtHarga.Text = ""

            strsql = "insert into History (Nama, Ic, Kod_Buku, Tajuk, Harga, Tarikh_Pinjam, Tarikh_Pulang) values (@1, @2, @3, @4, @5, @6, @7)"
            acscmd.CommandText = strsql
            acscmd.Connection = acsconn
            acscmd.Parameters.AddWithValue("@1", txtNama.Text)
            acscmd.Parameters.AddWithValue("@2", txtIC.Text)
            acscmd.Parameters.AddWithValue("@3", txtKod.Text)
            acscmd.Parameters.AddWithValue("@4", txtTajuk.Text)
            acscmd.Parameters.AddWithValue("@5", txtHarga.Text)
            acscmd.Parameters.AddWithValue("@6", DateTimePicker1.Value)
            acscmd.Parameters.AddWithValue("@7", DateTimePicker1.Value)
            acscmd.ExecuteNonQuery()
            acscmd.Dispose()
        End If
        acsconn.Close()

e31063a26aee9f8b47b4ed9a4c90150f

Recommended Answers

All 2 Replies

Its because of this line:

MsgBox("Peminjaman Berjaya!")
            txtNama.Text = ""
            txtIC.Text = ""
            txtKod.Text = ""
            txtTajuk.Text = ""
            txtHarga.Text = ""

You are setting textboxes to "" after executing in one table. So in other table it will get blank since query is after you made it to be empty.. Hope you understand :) Just commment that lines and check then if it works but it should

ooooohhh~~
ok Thanks!!!! its funny...
i dont know why i did't see that thing...Thanks uDevv! im trying to solve that thing in 3 days, after giveup and post it here...now the problem only that thing...

Be a part of the DaniWeb community

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