Solved

Scope Identity with MySQL table adapter

Posted on 2008-06-12
3
4,007 Views
Last Modified: 2013-12-17
I am having an issue witha table adapter and the scope identity when using a MySQL database.

If I was creating an Insert statement in a tableadapter to a MSSQL I woudl simply do a
Select Scope_Identity()...so that in teh TableAdapater the insert reads

INSERT INTO [tblApplicationType] ([ApplicationType], [Active]) VALUES (@ApplicationType, @Active);
SELECT SCOPE_IDENTITY()

with a Scalar execution mode and the Insert woudl return the value of teh primary key for that new inserted row...

However adding the

Select Scope_Identity()

to an insert statement when the table adapater is poitning to a MySQL table returns an error about incorrect syntax.

I need to return the value of the inserted row and capture it..Can someone tell me the correct syntax I need?

I have tried

INSERT INTO tblapplicationtype
                      (ApplicationType, Active)
VALUES     (@ApplicationType, @Active)
Select last_insert_id()

But that isnt working...returns and error trying to parse the query.

I am using the MySQL connector 5.2.2
0
Comment
Question by:Prysson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21770079
can you try this:
INSERT INTO tblapplicationtype
                      (ApplicationType, Active)
VALUES     (@ApplicationType, @Active);
Select last_insert_id();

Open in new window

0
 

Author Comment

by:Prysson
ID: 21770161
I could have deleted this question since I found the answer..but I want to add it to my knowledge base AND I want the answer to be available should anyone else have the same questions.

The answer is this.
INSERT INTO tblapplicationtype
                      (ApplicationType, Active)
VALUES     (@ApplicationType, @Active); SELECT     last_insert_id()

So Basically...just as with the MSSQL database you have to set the ExecutionMode to Scalar

Then add  ; SELECT     last_insert_id() to the end of the insert statement.  Mine was failing specifically because I wasnt puttin in the  ;


0
 

Author Comment

by:Prysson
ID: 21770174
He He...you answered just as I was writing the solution I found..Ill give you the credit..the answer you provided is the right one.

0

Featured Post

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question