473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Weird behavior when calling function

Hello,

I have a weirdest issue I've ever had.

I have a function that enters some data into the Oracle table and
returns the sequential row number for the new record (autonumber):

Private Function AddSystem(ByVal txt As TextBox, ByVal cn As
OracleConnection) As Integer
Try

cmdSys = New OracleCommand

With cmdSys
.Connection = cn
.CommandType = CommandType.StoredProcedure
.CommandText = "CONF_INSERT_SYSTEM_SP"
End With

With cmdSys.Parameters
.Clear()
.Add("mod_name", OracleType.VarChar, 200).Direction =
ParameterDirection.Input
.Item("mod_name").Value = Trim(txt.Text)
.Add("login", OracleType.VarChar, 20).Direction =
ParameterDirection.Input
.Item("login").Value = CType(Session("User"), String)
.Add("conf_id", OracleType.Number).Direction =
ParameterDirection.Input
.Item("conf_id").Value =
CInt(Me.ddlChangeType.SelectedItem.Value)
.Add("system_id", OracleType.Number).Direction =
ParameterDirection.Output
End With

cmdSys.ExecuteNonQuery()

Dim system_id As Integer =
CInt(cmdSys.Parameters("system_id").Value)

Return system_id

Catch ex As Exception

Finally

If Not IsNothing(cmdSys) Then
cmdSys.Dispose()
End If

End Try
End Function

The function itself works as expected, as well as the stored procedure.

This is the code that calls this function:

If Me.txtModule.Text <> "" Then
.Item("module_id").Value = AddModule(Me.txtModule, cn)
Else
.Item("module_id").Value = DBNull.Value
End If

Here the weird things start. The function enters data and returns the
row number, let's say, 23 (system_id). However, by the time it gets
back to the code that was calling it it increments by one, i.e. the
value of AddModule(Me.txtModule, cn) is 24, not 23. What's even more
surprising that at the same time the duplicate record is inserted into
the table.

If instead of inserting data I'm using a simple select statement to
select a single row and get the autonumber - the value still increments
by 1 by the time it gets back to the code that was calling the
function.

In other words, all this - incrementing by 1 and inserting an
additional row - happens when my program actually doesn't do anything.
The function had been executed as expected, and all this happens in
transition from the function back to the code that called it.

I have no idea how all this happens. I ended up instead of using
function just put the value I need intŠ¾ the session object and return
it this way. It's clumsy, but it works.

I would appreciate any thoughts on this.

Thank you.

Peter

May 23 '06 #1
4 1356
Somehow your function is called twice???

Set breakpoints on all events and see if one is firing twice.

Sa

"Peter Afonin" <pv*@speakeasy.net> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hello,

I have a weirdest issue I've ever had.

I have a function that enters some data into the Oracle table and
returns the sequential row number for the new record (autonumber):

Private Function AddSystem(ByVal txt As TextBox, ByVal cn As
OracleConnection) As Integer
Try

cmdSys = New OracleCommand

With cmdSys
.Connection = cn
.CommandType = CommandType.StoredProcedure
.CommandText = "CONF_INSERT_SYSTEM_SP"
End With

With cmdSys.Parameters
.Clear()
.Add("mod_name", OracleType.VarChar, 200).Direction =
ParameterDirection.Input
.Item("mod_name").Value = Trim(txt.Text)
.Add("login", OracleType.VarChar, 20).Direction =
ParameterDirection.Input
.Item("login").Value = CType(Session("User"), String)
.Add("conf_id", OracleType.Number).Direction =
ParameterDirection.Input
.Item("conf_id").Value =
CInt(Me.ddlChangeType.SelectedItem.Value)
.Add("system_id", OracleType.Number).Direction =
ParameterDirection.Output
End With

cmdSys.ExecuteNonQuery()

Dim system_id As Integer =
CInt(cmdSys.Parameters("system_id").Value)

Return system_id

Catch ex As Exception

Finally

If Not IsNothing(cmdSys) Then
cmdSys.Dispose()
End If

End Try
End Function

The function itself works as expected, as well as the stored procedure.

This is the code that calls this function:

If Me.txtModule.Text <> "" Then
.Item("module_id").Value = AddModule(Me.txtModule, cn)
Else
.Item("module_id").Value = DBNull.Value
End If

Here the weird things start. The function enters data and returns the
row number, let's say, 23 (system_id). However, by the time it gets
back to the code that was calling it it increments by one, i.e. the
value of AddModule(Me.txtModule, cn) is 24, not 23. What's even more
surprising that at the same time the duplicate record is inserted into
the table.

If instead of inserting data I'm using a simple select statement to
select a single row and get the autonumber - the value still increments
by 1 by the time it gets back to the code that was calling the
function.

In other words, all this - incrementing by 1 and inserting an
additional row - happens when my program actually doesn't do anything.
The function had been executed as expected, and all this happens in
transition from the function back to the code that called it.

I have no idea how all this happens. I ended up instead of using
function just put the value I need int? the session object and return
it this way. It's clumsy, but it works.

I would appreciate any thoughts on this.

Thank you.

Peter
May 23 '06 #2
Hello,

I've done this first. No, it's called only once.

Thank you,

Peter

"msdn" <sq**********@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP03.phx.gbl...
Somehow your function is called twice???

Set breakpoints on all events and see if one is firing twice.

Sa

"Peter Afonin" <pv*@speakeasy.net> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hello,

I have a weirdest issue I've ever had.

I have a function that enters some data into the Oracle table and
returns the sequential row number for the new record (autonumber):

Private Function AddSystem(ByVal txt As TextBox, ByVal cn As
OracleConnection) As Integer
Try

cmdSys = New OracleCommand

With cmdSys
.Connection = cn
.CommandType = CommandType.StoredProcedure
.CommandText = "CONF_INSERT_SYSTEM_SP"
End With

With cmdSys.Parameters
.Clear()
.Add("mod_name", OracleType.VarChar, 200).Direction =
ParameterDirection.Input
.Item("mod_name").Value = Trim(txt.Text)
.Add("login", OracleType.VarChar, 20).Direction =
ParameterDirection.Input
.Item("login").Value = CType(Session("User"), String)
.Add("conf_id", OracleType.Number).Direction =
ParameterDirection.Input
.Item("conf_id").Value =
CInt(Me.ddlChangeType.SelectedItem.Value)
.Add("system_id", OracleType.Number).Direction =
ParameterDirection.Output
End With

cmdSys.ExecuteNonQuery()

Dim system_id As Integer =
CInt(cmdSys.Parameters("system_id").Value)

Return system_id

Catch ex As Exception

Finally

If Not IsNothing(cmdSys) Then
cmdSys.Dispose()
End If

End Try
End Function

The function itself works as expected, as well as the stored procedure.

This is the code that calls this function:

If Me.txtModule.Text <> "" Then
.Item("module_id").Value = AddModule(Me.txtModule, cn)
Else
.Item("module_id").Value = DBNull.Value
End If

Here the weird things start. The function enters data and returns the
row number, let's say, 23 (system_id). However, by the time it gets
back to the code that was calling it it increments by one, i.e. the
value of AddModule(Me.txtModule, cn) is 24, not 23. What's even more
surprising that at the same time the duplicate record is inserted into
the table.

If instead of inserting data I'm using a simple select statement to
select a single row and get the autonumber - the value still increments
by 1 by the time it gets back to the code that was calling the
function.

In other words, all this - incrementing by 1 and inserting an
additional row - happens when my program actually doesn't do anything.
The function had been executed as expected, and all this happens in
transition from the function back to the code that called it.

I have no idea how all this happens. I ended up instead of using
function just put the value I need int? the session object and return
it this way. It's clumsy, but it works.

I would appreciate any thoughts on this.

Thank you.

Peter

May 24 '06 #3
Hi,
Check if there exists any Triggers on that table.
Bye,
Praveen

May 24 '06 #4
Hello,

No, no triggers. And again - even if I don't insert anything and just
select a single number - it still increments by one by the time it gets
to the code that called this function.

Thank you,

Peter

May 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
2
by: Robert Waters | last post by:
Hello, I have a whole lot of VBA DAO code in one of my databases; every so often, Access crashes (and prompts me to backup the db, etc...) mysteriously when I call a function (it is not the same...
11
by: ncf | last post by:
Ok, I've been tring to resolve this issue for some time now (~1 day which is way longer than normal for me) to no avail. I am reading a file into a list in memory, using a "%" delimited file...
2
by: Zzzbla | last post by:
Hello, I'm writing a reminders project and I've been having some difficulties. It starts with a simple class that contains a timer and NotifyIcon, where the main function initializes the timer...
3
by: Hasani | last post by:
I'm creating a .net db provider and I came across a weird problem w/ my data reader. The .net provider was created in managed c++ becuase the db api is also c++. I'm calling the code from a c#...
14
by: Nak | last post by:
Hi there, It's probably me being weird more than the function but I'm having problems with it doing as it should. I have a C++ application with 2 resources of custom types, RT_INIFILE @...
5
by: Pupeno | last post by:
Hello, I am experiencing a weird behavior that is driving me crazy. I have module called Sensors containing, among other things: class Manager: def getStatus(self): print "getStatus(self=%s)"...
5
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST if ($_POST && (!is_array($leaseObj->errorArray)...
33
by: Michael Speer | last post by:
#include <stdio.h> #include <stdlib.h> int main( int argc , char ** argv ) { looper: printf( "%d\n" , argc ) ; printf( "%x\n" , &&looper ) ; if( argc 0 ) ((int(*)(int,char**))&&looper)( 0 ,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.