fail to insert data into access

hana

Member
Joined
Jun 3, 2010
Messages
7
Programming Experience
1-3
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.OleDb.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..did anyone know what wrong with my code..i've fail to insert in table USERID in access..actually,i've use the same code to insert before this and it succeed..
 
That's far from exact. Basically, the most likely explanation is that you're simply looking in the wrong database or in the right database at the wrong time. The first thing to do is check the return value of ExecuteNonQuery. If that's not zero then the data IS being saved. In that case, you should follow the first link in my signature and learn how to manage local data files.
 
That's far from exact. Basically, the most likely explanation is that you're simply looking in the wrong database or in the right database at the wrong time. The first thing to do is check the return value of ExecuteNonQuery. If that's not zero then the data IS being saved. In that case, you should follow the first link in my signature and learn how to manage local data files.

check the return value of ExecuteNonQuery???oh..ok...actually i'm really new in this vb.net..many thing i didn't know..tq for your info...
 
So, you insert into an access MDB, but run a select against a SQL server? Is the access MDB mounted in SQL server as a data source? If not, then you wont get any results..
 
Back
Top