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

Microsoft Data Access Blocks (SqlHelper) - Executing 2 SQL commands

Microsoft Data Access Blocks (SqlHelper) you can do an insert and get
the new row ID without using a stored procedure?

DataMembers.Car_IDObject = SqlHelper.ExecuteScalar( _connectionString ,
"INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
INTEGER) ", FillSqlParameter());

Is there a new line symbol I can add before the SELECT, like a ';'
or something?

--
Sincerely,
David Dimmer

Quality Builders of ASP.NET Web Sites

B: 414.769.1233
M: 414.688.3941
W: http://www.milwaukeewebdesigners.com/

Nov 19 '05 #1
4 2852
";"
or
";GO"

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"FyinsFlip" <go********@fyin.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Microsoft Data Access Blocks (SqlHelper) you can do an insert and get
the new row ID without using a stored procedure?

DataMembers.Car_IDObject = SqlHelper.ExecuteScalar( _connectionString ,
"INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
INTEGER) ", FillSqlParameter());

Is there a new line symbol I can add before the SELECT, like a ';'
or something?

--
Sincerely,
David Dimmer

Quality Builders of ASP.NET Web Sites

B: 414.769.1233
M: 414.688.3941
W: http://www.milwaukeewebdesigners.com/

Nov 19 '05 #2
Also, a word to the wise don't use @@Identity in SQL Server 2000:

http://weblogs.sqlteam.com/travisl/a...10/29/405.aspx

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:uS**************@TK2MSFTNGP15.phx.gbl...
";"
or
";GO"

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"FyinsFlip" <go********@fyin.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Microsoft Data Access Blocks (SqlHelper) you can do an insert and get
the new row ID without using a stored procedure?

DataMembers.Car_IDObject = SqlHelper.ExecuteScalar( _connectionString ,
"INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
INTEGER) ", FillSqlParameter());

Is there a new line symbol I can add before the SELECT, like a ';'
or something?

--
Sincerely,
David Dimmer

Quality Builders of ASP.NET Web Sites

B: 414.769.1233
M: 414.688.3941
W: http://www.milwaukeewebdesigners.com/


Nov 19 '05 #3
your syntax is correct, no linebreaks are required to seperate statements, a
space is fine. ExecuteScalar returns the first column of the first row of
the first result set. the way you have the sql coded, you get two result
sets, but thats easily fixed. try:

DataMembers.Car_IDObject = SqlHelper.ExecuteScalar( _connectionString ,
"set nocount on INSERT INTO tCar (name) VALUES ('Ford') SELECT
CAST(scope_identity() AS
INTEGER) ",
FillSqlParameter());
-- bruce (sqlwork.com)
"FyinsFlip" <go********@fyin.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
| Microsoft Data Access Blocks (SqlHelper) you can do an insert and get
| the new row ID without using a stored procedure?
|
| DataMembers.Car_IDObject = SqlHelper.ExecuteScalar( _connectionString ,
| "INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
| INTEGER) ", FillSqlParameter());
|
| Is there a new line symbol I can add before the SELECT, like a ';'
| or something?
|
| --
| Sincerely,
| David Dimmer
|
| Quality Builders of ASP.NET Web Sites
|
| B: 414.769.1233
| M: 414.688.3941
| W: http://www.milwaukeewebdesigners.com/
|
Nov 19 '05 #4
You can separate commands with a ";", if you want to string commands.
Personally, I would go to stored procedures, but you can string any number of
commands. WHen you complete the batch, add a "; GO" to the end to make sure
the entire batch runs.

Also, use "SCOPE_IDENTITY" instead of "@@IDENTITY", as high traffic sites
could yield a wrong answer.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"FyinsFlip" wrote:
Microsoft Data Access Blocks (SqlHelper) you can do an insert and get
the new row ID without using a stored procedure?

DataMembers.Car_IDObject = SqlHelper.ExecuteScalar( _connectionString ,
"INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
INTEGER) ", FillSqlParameter());

Is there a new line symbol I can add before the SELECT, like a ';'
or something?

--
Sincerely,
David Dimmer

Quality Builders of ASP.NET Web Sites

B: 414.769.1233
M: 414.688.3941
W: http://www.milwaukeewebdesigners.com/

Nov 19 '05 #5

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

Similar topics

2
by: BStorm | last post by:
I ran into a maddening bug that I finally tracked down to Microsoft's Data Access Blocks. It is in the SQL Helper UpdateDataSet method as follows: Microsoft Code: #region UpdateDataset public...
6
by: Dan | last post by:
Hi Is Microsoft's Sqlhelper.cs (Microsoft Application Blocks for .NET - Data Access) Thread safe? The documentation has no references to threads. Thanks Dan
8
by: poifull | last post by:
Is anyone using the Microsoft Enterprise Library? If yes, do you like it or not? Any feedback will be appreciated.
1
by: EO | last post by:
I am trying to use the MSFT data access application block on 3 machines. Machine 1: Sandbox environment; I installed the application block with the msi. The Sqlhelper class compiles & runs...
7
by: Neven Klofutar | last post by:
Hi, I have a problem with SqlHelper.ExecuteScalar ... When I try to execute SqlHelper.ExecuteScalar I get this message: "System.InvalidCastException: Object must implement IConvertible.". ...
2
by: Tim::.. | last post by:
Can someone tell me how you change this code for an Oledb connection rather than SQL Server. The code currently uses Microsoft.Data.Access.Application.Block and the SQLHelper object... I need to...
5
by: lds | last post by:
I am in the process of trying to migrate some of our existing .NET applications from version 1.1 to 2.0. In our 1.1 apps we have a common assembly that uses the sqlhelper.vb class from the...
6
by: Milsnips | last post by:
hi there, i;m doing a loop of a few hundred records and inserting into database using the MS data dll, and the following line dim sql as string = "mysql code is here..."...
8
by: Matt | last post by:
I am developing couple intranet site. Cant decide what to use to get the Data I will be using Data Layer to get,update, insert, delete and report type queries.. Most expensive table will have 1...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
1
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.