Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Fail to insert data into Access

Function selectDB17()
Dim cn As New SqlConnection
Dim cmd As New SqlCommand

cn.ConnectionString = ("server=EKS-HQ;database=BGB;user id=administrator;password=admineks2005")
cn.Open()
cmd.Connection = cn
cmd.CommandText = "SELECT KODSTATE,USERID,PASSWORD,KUMPULAN FROM USERID"
Dim lrd As SqlDataReader = cmd.ExecuteReader()
Try
Do While lrd.Read()
If lrd.HasRows Then
a = lrd("KODSTATE")
b = lrd("USERID")
c = lrd("PASSWORD")
d = lrd("KUMPULAN")
Else
MsgBox("Tiada Data")
End If
insertDB17()
Loop
Catch ex As Exception
MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records")
Finally
cn.Close()
End Try

End Function
Function insertDB17()
Dim con As OleDb.OleDbConnection
Dim str As String
Dim cmd As OleDb.OleDbCommand
Try
con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleD b.4.0;data source=" & strsaveDB & "\" & strnameDB & ".mdb")
con.Open()
str = "insert into USERID(KODSTATE,USERID,PASSWORD,KUMPULAN)values('" & a & "' ,'" & b & "','" & c & "','" & d & "')"
cmd = New OleDb.OleDbCommand(str, con)
cmd.ExecuteNonQuery()
Catch
End Try
con.Close()
End Function


=================================================
Hi there. Does anyone know what's wrong with my code. I fail to insert in table USERID in Access. Actually, I've use the same code to insert before this and it succeeded.
Posted
Updated 13-Jul-10 0:02am
v3
Comments
Estys 13-Jul-10 4:35am    
I don't know if it has to do with copy/paste but "Microsoft.Jet.OleD b.4.0" doesn't look good. Could you also put the code in
 tags? Thank you.
Simon_Whale 13-Jul-10 4:37am    
what is the error message..?
hana_84 13-Jul-10 4:54am    
actually,the code run well and it don't have any error,just the data can't be insert into access..it mean that after all the process finish,the USERID table still emtpy..

If I were you, I'd try to remove the try/catch in insertDB17. As it is now, you might be getting an error, but you just ignore it...
 
Share this answer
 
Comments
hana_84 13-Jul-10 20:50pm    
when i remove try/catch there is an error.."error retrieving record...
in that case one step that what I would be tempted to do is put a breakpoint on your str = "insert..."

from a quick watch i would copy and paste the sql statement that your program has created into access and try to executing the statement there

does this cause any errors?

As something has to be stopping the insert work
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900