Hello,
i have writen a little function to check if something exist in my access db, if it does not exist then it have to be created.
this is the code i wrote:
i've put some msgbox's in it to check witch one it takes but it keeps taking 1 so that means the record exist but i'm 100% sure it does not...
Ive found out that when i put a msgbox between "On Error GoTo failedtank" and "rs.Fill(dt)" it works.. so i think it is a problem with the speed off vb.net that access doesn't have the time to work..
Anyone any idea?
Greetz,
Jos Vink
Sorry for my bad english i'm dutch
i have writen a little function to check if something exist in my access db, if it does not exist then it have to be created.
this is the code i wrote:
Public Function tankstationexist(ByVal tankstation As String)
con.Open()
'controleren of tankstation bestaat in db
Dim dt As New DataTable("tankstations")
Dim rs As OleDb.OleDbDataAdapter
rs = New OleDb.OleDbDataAdapter("SELECT * FROM tankstations where naam='" & tankstation & "'", con)
On Error GoTo failedtank
rs.Fill(dt)
'verbinding verbreken
con.Close()
'functie afsluiten
MsgBox(1)
rs.Dispose()
Exit Function
failedtank:
MsgBox(2)
'bestaat tankstation niet dan word de waarde aangemaakt
Dim rs2 As New OleDb.OleDbCommand(
"INSERT INTO tankstations (naam) VALUES ('" &
tankstation & "')", con)
'Het SQL command uitvoeren
rs2.ExecuteNonQuery()
'Verbinding verbreken
rs.Dispose()
rs2.Dispose()
con.Close()
End Function
i've put some msgbox's in it to check witch one it takes but it keeps taking 1 so that means the record exist but i'm 100% sure it does not...
Ive found out that when i put a msgbox between "On Error GoTo failedtank" and "rs.Fill(dt)" it works.. so i think it is a problem with the speed off vb.net that access doesn't have the time to work..
Anyone any idea?
Greetz,
Jos Vink
Sorry for my bad english i'm dutch