how inserting multiple clients in my access database in asp.net?

  • Thread starter Thread starter Laura
  • Start date Start date
L

Laura

Guest
I am trying to fill my table clients but I only can fill in one !!!!
can you help me please?

Protected Sub cmdversturen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdversturen.Click

Dim clientid As Integer = 0
Dim naam As String = txtNaam.Text
Dim voornaam As String = txtVoornaam.Text
Dim geslacht As String = drpGeslacht.Text
Dim adres As String = txtAdres.Text
Dim postcode As String = txtPostcode.Text
Dim gemeente As String = txtGemeente.Text
Dim land As String = txtLand.Text
Dim tel As String = txtTelefoon.Text
Dim gsm As String = txtGsm.Text
Dim email As String = txtEmail.Text
Dim gebruikersnaam As String = txtgebruikersnaam.Text
Dim wachtwoord As String = txtwachtwoord.Text

If (clientid > 0) Then
clientid = clientid + 1
Else
clientid = 1
End If
serviceClient.insertingclient(clientid, naam, voornaam, geslacht, adres, postcode, gemeente, land, tel, gsm, email, gebruikersnaam, wachtwoord)
'serviceClient.updateclient(clientid, naam, voornaam, geslacht, adres, postcode, gemeente, land, tel, gsm, email, gebruikersnaam, wachtwoord)

Response.Redirect("ingelogd.aspx")
 
I don't think you are managing the id field correctly. It appears you are either updating the same record over and over or getting a constraint violation error because you are passing the same ID value every time this sub is called. Note, your code is always passing clientid=1.

Dim clientid As Integer = 0'defined in scope as 0
If (clientid > 0) Then'can't be >0 because of previous line
clientid = clientid + 1
Else
clientid = 1'This is executing every time
End If

I think the easiest fix for this scenario is to set your ID field as an identity with an auto increment value and let the database handle the value. Then you simply remove the ID references from your code.

Alternatively (my preference) is to use GUID's for an ID field. I think the only way to use GUID's with Access is to set the ID field as a varchar(34) and pass a new GUID from your code. For example, ID as string = GUID.NewGuid.ToString().
 
Back
Top