473,394 Members | 1,852 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,394 software developers and data experts.

Using Scope_Identity with a SQLDataSource in ASP.NET

I'm combining a "SELECT Scope_Identity..." statement with an insert
statement in my InsertCommand. When I try to retrieve the value into a

variable, it generates an error stating that my collumn
"myScope_Identity" is invalid. If I run the SQL statements in Query
Analyzer, it works just fine. In Enterprise Manager, it does not
generate an error but it doesn't return any data back.

Any help would be greatly appreciated.
Luis
Dim myInsertCommand As String
Dim myCM_FName As String = Me.txtCM_FName_II.Text
Dim myCM_LName As String = Me.txtCM_LName_II.Text
Dim myCM_MInit As String = Me.txtCM_MInit_II.Text
Dim myCM_NickName As String = Me.txtCM_Nickname_II.Text
Dim myCM_Comments As String = Me.txtCM_Comments_ET.Text
Dim myCM_AddedBy As String = "0"
Dim myCM_ChangedBy As String = "0"
Dim myCM_ChangedByDate As Date = Now()
myInsertCommand = "INSERT INTO tbl_Customer_CustomerMaster "
myInsertCommand += " (CM_FName, CM_LName,
CM_MInit, CM_NickName, CM_Comments, CM_AddedBy, CM_ChangedBy,
CM_ChangedByDate) "
myInsertCommand += "VALUES (N'" & myCM_FName & "', N'" &
myCM_LName & "', N'" & myCM_MInit & "', N'" & myCM_NickName & "', "
myInsertCommand += " N'" & myCM_Comments & "', N'0',

N'0', "
myInsertCommand += " { fn NOW() }); "
myInsertCommand += "SELECT SCOPE_IDENTITY() AS
myScope_Identity; "
Me.sdsInsertCustomerEntity.InsertCommand = myInsertCommand
'Programmatically access the SqlDataSource - get back a
DataView
Dim myScopeIdentity As String
Try
Me.sdsInsertCustomerEntity.Insert()
Dim dv As DataView =
CType(Me.sdsInsertCustomerEntity.Select(DataSource SelectArguments.Empty),

DataView)
For Each dr As DataRow In dv.Table.Rows
myScopeIdentity = dr("myScope_Identity").ToString()
Next
Me.EditMSG.Text = myScopeIdentity & " - <u>" &
Me.txtCM_LName_II.Text & ", " & Me.txtCM_FName_II.Text & "</uwas
inserted successfully!!!"
Catch ex As Exception
Me.EditMSG.Text = "ERROR - Please check data and try
again!"
End Try

Jan 5 '07 #1
0 1476

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

Similar topics

9
by: Roger Withnell | last post by:
I'm inserting a new record into an MS SQL database table and I want to obtain the new records autonumber immediately afterwards, as follows: MadminRS.CursorLocation = adUseServer...
4
by: Scrappy | last post by:
I have an ASP front end on SQL 2000 database. I have a form that submits to an insert query. The entry field is an "identity" and the primary key. I have used scope_identity() to display the...
6
by: Hardy Wang | last post by:
Hi all, I have the following codes, but SCOPE_IDENTITY() just returns NULL to me. If I comment out SCOPE_IDENTITY() line and run @@IDENTITY line, it works fine!! Since I have a trigger on the...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
3
by: Jim Andersen | last post by:
Hi, I would appreciate if someone could explain this behaviour, and maybe offer a better solution. I have been working with the GridView control. And SqlDataSource. It works great if I do:...
17
by: Rico | last post by:
Hello, I am in the midst of converting an Access back end to SQL Server Express. The front end program (converted to Access 2003) uses DAO throughout. In Access, when I use recordset.AddNew I...
5
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
6
by: tshad | last post by:
I was looking at a page that showed how to set up a custom event and it seems to work ok. But I am not sure how I would use it. How would I subscribe to it. There is actual action (such as...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.