473,563 Members | 2,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Execu teScalar( _connectionStri ng ,
"INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
INTEGER) ", FillSqlParamete r());

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 2866
";"
or
";GO"

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"FyinsFlip" <go********@fyi n.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.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.Execu teScalar( _connectionStri ng ,
"INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
INTEGER) ", FillSqlParamete r());

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_da rkfalz.com> wrote in message
news:uS******** ******@TK2MSFTN GP15.phx.gbl...
";"
or
";GO"

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"FyinsFlip" <go********@fyi n.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.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.Execu teScalar( _connectionStri ng ,
"INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
INTEGER) ", FillSqlParamete r());

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.Execu teScalar( _connectionStri ng ,
"set nocount on INSERT INTO tCar (name) VALUES ('Ford') SELECT
CAST(scope_iden tity() AS
INTEGER) ",
FillSqlParamete r());
-- bruce (sqlwork.com)
"FyinsFlip" <go********@fyi n.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.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.Execu teScalar( _connectionStri ng ,
| "INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
| INTEGER) ", FillSqlParamete r());
|
| 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.Execu teScalar( _connectionStri ng ,
"INSERT INTO tCar (name) VALUES ('Ford') SELECT CAST(@@Identity AS
INTEGER) ", FillSqlParamete r());

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
374
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 static void UpdateDataset(SqlCommand insertCommand, SqlCommand deleteCommand, SqlCommand updateCommand, DataSet dataSet, string tableName) { if(...
6
2140
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
4082
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
1920
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 great! (Also the SqlhelperParameterCache class; I'll refer to them collectively as the SqlHelper class.) I'm using unmodified application block code in...
7
11995
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.". Help ... Thanx, Neven
2
2495
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 use this with an access database! reader = SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings("strConn"), CommandType.StoredProcedure,...
5
1809
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 Micosoft Application Block provided for version 1.1. When I try to migrate I get a few errors, so I thought that maybe I should just try using the new...
6
5654
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..." microsoft.applicationblocks.data.sqlhelper.executenonquery(configurationsettings.appsetting("db"),commandtype.text,sql) After a large number of records, i see its not...
8
1882
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 mil records.. Just a couple of tables will have that amount of data.. What would be affecient to use between 1. Code behind to call...
0
7580
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5481
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3634
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.