| Newbie | | Join Date: May 2009
Posts: 1
| |
Hello,
Trying to just insert a simple record in DB and it fails. When I set debugger on, I see that execution jumps out by IntakeNummer to the Catch and of course, assigns value -1 to IntakeNummer. As if it was impossible to increment or even read de identity column! In my DB, IntakeID is my identity column (1,1).
Underneath the vb.net code that fails. Can anyone help me? What am I doing wrong?
--------------------------------------------------------------- -
Public Function SetIntake(ByVal ProjectNummer As Integer, ByVal Status As String, ByVal DatumIntake As String, ByVal TelefonischAfspraak As String, _
-
ByVal Doelgroep As String, ByVal AantalDeelnemers As Integer, ByVal DataUitvoering As String, _
-
ByVal Tijden As String, ByVal OndersteuningBij As String, ByVal HandvattenVoor As String, _
-
ByVal LastigeSituaties As String, ByVal Opmerkingen As String, ByVal ActeurNodig As String, _
-
ByVal DatumAfgehandeld As String, ByVal ParamKlantID As Integer) As Integer
-
-
Dim IntakeNummer As Integer = -1
-
Dim connectionString As String = getConnectionString()
-
Dim connection As New SqlConnection(connectionString)
-
Dim Query As New String("Insert Into Intake(" _
-
& "ProjectNummer, Status, DatumIntake, TelefonischAfspraak, " _
-
& "Doelgroep, AantalDeelnemers, DataUitvoering, Tijden, " _
-
& "OndersteuningBij, HandvattenVoor, LastigeSituaties, Opmerkingen, " _
-
& "ActeurNodig, DatumAfgehandeld, KlantID " _
-
& ") values ('" & ProjectNummer & "'," _
-
& "'" & Status & "'," _
-
& "'" & DatumIntake & "'," _
-
& "'" & TelefonischAfspraak & "'," _
-
& "'" & Doelgroep & "'," _
-
& "'" & AantalDeelnemers & "'," _
-
& "'" & DataUitvoering & "'," _
-
& "'" & Tijden & "'," _
-
& "'" & OndersteuningBij & "'," _
-
& "'" & HandvattenVoor & "'," _
-
& "'" & LastigeSituaties & "'," _
-
& "'" & Opmerkingen & "'," _
-
& "'" & ActeurNodig & "'," _
-
& "'" & DatumAfgehandeld & "'" _
-
& "'" & ParamKlantID & "'")
-
-
Query = Query + New String("; Select @@IDENTITY")
-
-
-
Dim identity As Integer = -1
-
Dim Command As New SqlCommand
-
-
Try
-
connection = New SqlConnection(connectionString)
-
Command.CommandType = CommandType.Text
-
-
Command.CommandText = Query
-
Command.Connection = connection
-
Command.Connection.Open()
-
'JUMPS HERE TO CATCH AND ASSIGNS VALUE -1 TO INTAKENUMMER
-
IntakeNummer = Integer.Parse(Command.ExecuteScalar().ToString())
-
Command.ExecuteNonQuery()
-
Command.Connection.Close()
-
Catch ex As Exception
-
Dim err As String
-
err = ex.Message()
-
Return -1
-
End Try
-
-
Return IntakeNummer
-
End Function
|