473,406 Members | 2,467 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,406 software developers and data experts.

ASP.NET 2.0 Return Values

Have the following code to extract the ID of a member once a new member has
been inserted into the SQL 2005 Express database.

Dim myID As String = ""
Dim myConnString As String =
ConfigurationManager.ConnectionStrings("Connection String").ToString
Dim mySelectQuery As String = "SELECT IDENT_CURRENT('Members')"
Dim myConnection As New Data.SqlClient.SqlConnection(myConnString)
Dim myCommand As New Data.SqlClient.SqlCommand(mySelectQuery, myConnection)
Dim myReader As Data.SqlClient.SqlDataReader

myConnection.Open()
myReader = myCommand.ExecuteReader()
myID = myReader.GetInt32(0).ToString
myReader.Close()
myConnection.Close()

Cannot get the required value as keep getting the following error message:-

In order to evaluate an indexed property, the property must be qualified and
the arguments must be explicitly supplied by the user

Thanks
Kevin
Apr 29 '06 #1
3 4049
Kevin wrote:
Have the following code to extract the ID of a member once a new member has
been inserted into the SQL 2005 Express database.

Dim myID As String = ""
Dim myConnString As String =
ConfigurationManager.ConnectionStrings("Connection String").ToString
Dim mySelectQuery As String = "SELECT IDENT_CURRENT('Members')"
Dim myConnection As New Data.SqlClient.SqlConnection(myConnString)
Dim myCommand As New Data.SqlClient.SqlCommand(mySelectQuery, myConnection)
Dim myReader As Data.SqlClient.SqlDataReader

myConnection.Open()
myReader = myCommand.ExecuteReader()
myID = myReader.GetInt32(0).ToString
myReader.Close()
myConnection.Close()

Cannot get the required value as keep getting the following error message:-

In order to evaluate an indexed property, the property must be qualified and
the arguments must be explicitly supplied by the user

Thanks
Kevin


The ident_current function returns an id created in any session. That
means that you get the last id created regardless if it was created in
the same session or not. What you want to use is scope_identity(), that
returns the last id created in the current scope.

You have to call the Read method of the datareader before you can get
any data from it. Or better yet, use ExecuteScalar instead.

If you still get an error message, you have to tell when the error
occurs and where the error message comes from.
Apr 29 '06 #2
Thanks for your help.
Used the .Read() method and works fine.
Tried the ExecuteScalar and got millions of errors.

Used SELECT IDENT_CURRENT('Members') because then will get last ID for the
table where SCOPE_IDENTITY returns last ID of any table.
Assume because opening new connection for the datareader it is not in the
same scope and could get an update from another user??
ASP was easier that this! - Phew!!

Thanks again
Kevin

"Göran Andersson" <gu***@guffa.com> wrote in message
news:uf**************@TK2MSFTNGP02.phx.gbl...
Kevin wrote:
Have the following code to extract the ID of a member once a new member
has been inserted into the SQL 2005 Express database.

Dim myID As String = ""
Dim myConnString As String =
ConfigurationManager.ConnectionStrings("Connection String").ToString
Dim mySelectQuery As String = "SELECT IDENT_CURRENT('Members')"
Dim myConnection As New Data.SqlClient.SqlConnection(myConnString)
Dim myCommand As New Data.SqlClient.SqlCommand(mySelectQuery,
myConnection)
Dim myReader As Data.SqlClient.SqlDataReader

myConnection.Open()
myReader = myCommand.ExecuteReader()
myID = myReader.GetInt32(0).ToString
myReader.Close()
myConnection.Close()

Cannot get the required value as keep getting the following error
message:-

In order to evaluate an indexed property, the property must be qualified
and the arguments must be explicitly supplied by the user

Thanks
Kevin


The ident_current function returns an id created in any session. That
means that you get the last id created regardless if it was created in the
same session or not. What you want to use is scope_identity(), that
returns the last id created in the current scope.

You have to call the Read method of the datareader before you can get any
data from it. Or better yet, use ExecuteScalar instead.

If you still get an error message, you have to tell when the error occurs
and where the error message comes from.

Apr 29 '06 #3
Kevin wrote:
Thanks for your help.
Used the .Read() method and works fine.
Tried the ExecuteScalar and got millions of errors.
Then don't sweat it. Using a DataReader is just as good a solution. Only
it's a bit less code if you use ExecuteScalar.
Used SELECT IDENT_CURRENT('Members') because then will get last ID for the
table where SCOPE_IDENTITY returns last ID of any table.
Assume because opening new connection for the datareader it is not in the
same scope and could get an update from another user??
If you use ident_current you will get the wrong id sooner or later if
there are simultanious connections to the database. It works most of the
time, but not always. (And we all know that bugs that only occur
sometimes are the hardest ones to find.)

You should use the same connection to get the id that you used to add
the record, or you will not be in the same scope. The only truly safe
way to get the correct id is to use scope_identity in the same connection.

(Using @@identity will also work as long as you don't add records in
triggers, but why use it when scope_identity does it better.)
ASP was easier that this! - Phew!!
The database part is the same, it has never changed.

ASP might seem easier, but it's really not. There are so much more that
you have to know about ASP before you really can build a robust system.
With ASP.NET it's robust to start with, you just have to keep it robust,
you don't have to build the robustness from scratch.
Thanks again
Kevin

"Göran Andersson" <gu***@guffa.com> wrote in message
news:uf**************@TK2MSFTNGP02.phx.gbl...
Kevin wrote:
Have the following code to extract the ID of a member once a new member
has been inserted into the SQL 2005 Express database.

Dim myID As String = ""
Dim myConnString As String =
ConfigurationManager.ConnectionStrings("Connection String").ToString
Dim mySelectQuery As String = "SELECT IDENT_CURRENT('Members')"
Dim myConnection As New Data.SqlClient.SqlConnection(myConnString)
Dim myCommand As New Data.SqlClient.SqlCommand(mySelectQuery,
myConnection)
Dim myReader As Data.SqlClient.SqlDataReader

myConnection.Open()
myReader = myCommand.ExecuteReader()
myID = myReader.GetInt32(0).ToString
myReader.Close()
myConnection.Close()

Cannot get the required value as keep getting the following error
message:-

In order to evaluate an indexed property, the property must be qualified
and the arguments must be explicitly supplied by the user

Thanks
Kevin

The ident_current function returns an id created in any session. That
means that you get the last id created regardless if it was created in the
same session or not. What you want to use is scope_identity(), that
returns the last id created in the current scope.

You have to call the Read method of the datareader before you can get any
data from it. Or better yet, use ExecuteScalar instead.

If you still get an error message, you have to tell when the error occurs
and where the error message comes from.


Apr 30 '06 #4

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

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
1
by: Jack Addington | last post by:
I have a 3rd party object that fires an itemchanged event when someone edits some data on a form. This event has a custom eventArgs that has a field called ActionCode. In the code of the event,...
5
by: Edward Diener | last post by:
I am gathering from the documentation that return values from __events are not illegal but are frowned upon in .NET. If this is the case, does one pass back values from an event handler via...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
43
by: Tim Chase | last post by:
Just as a pedantic exercise to try and understand Python a bit better, I decided to try to make a generator or class that would allow me to unpack an arbitrary number of calculatible values. In...
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
80
by: xicloid | last post by:
I'm making a function that checks the input integer and returns the value if it is a prime number. If the integer is not a prime number, then the function should return nothing. Problem is, I...
2
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne ...
4
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.