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