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

What's wrong with my SqlCommand?

Hi,

In my codes:
=======================================
myConn.Open();
SqlTransaction MyTrans= myConn.BeginTransaction();

SqlCommand myCommand = new SqlCommand("ZZZ15UserLog",myConn);
myCommand.CommandType= CommandType.StoredProcedure;
SqlDataReader myReader;

myCommand.Transaction=MyTrans;
try
{
myCommand.ExecuteReader();
MyTrans.Commit();
}
catch { }
========================================

That will result in some error, however, if I change the ExecuteReader() to
ExecuteNonQuery(),
it will be fine.
Would someone tell me what have I done wrong with my code?
Thanks for help.
Jason


Dec 14 '06 #1
2 1136
"Jason Huang" <Ja************@hotmail.comschrieb im Newsbeitrag
news:Ok**************@TK2MSFTNGP06.phx.gbl...
Hi,

In my codes:
=======================================
myConn.Open();
SqlTransaction MyTrans= myConn.BeginTransaction();

SqlCommand myCommand = new SqlCommand("ZZZ15UserLog",myConn);
myCommand.CommandType= CommandType.StoredProcedure;
SqlDataReader myReader;

myCommand.Transaction=MyTrans;
try
{
myCommand.ExecuteReader();
MyTrans.Commit();
}
catch { }
========================================

That will result in some error,
<snip>
What is the error? The message and the type of the exception will give
information about what went wrong.

If ExecuteReader failed but ExecuteNonQuery not, then maybe the procedure
doesn't return any result.

Dec 14 '06 #2
I would hazard a guess that the exception relates to concurrent
commands, and that the reader needs to be Close()d / Dispose()d to
release the connection. In this case, ExecuteNonQuery would seem more
appropriate.

Marc
Dec 14 '06 #3

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

Similar topics

9
by: Mike L | last post by:
I tried a sample of code in MSDN magazine, but now I'm stuck. What code has the best performance to populate a Data Grid with a SP? Below is the code I have, which might be completing the wrong...
9
by: Alan Silver | last post by:
hello, I am writing my first real ASP.NET application, but am getting a bit confused with ADO.NEt and the best way to use it. My old method (with Classic ASP) was to have a function that you...
3
by: Terry Olsen | last post by:
I've got 2 different web pages, both updating the same SQL database. One is for the Technician and one is for the Manager. The technician's update page works fine but the Manager's update page...
9
by: D. Shane Fowlkes | last post by:
I'm not new to ASP or MSSQL but fairly new to using Stored Procedures. I've got a T-SQL book on order from Amazon but it's still not here. I have a SP which updates a record. As far as I can...
9
by: rcoco | last post by:
Hi, I'm just wondering if I'm on the write truck. this code is ment to look for an ID number in the datagrid that matches the the ID number that is in the textbox I created. But it's not...
4
navanova
by: navanova | last post by:
I'm tring to insert to SQL server 2000 a data from a VB.net form. when i tried to run it , it says "Invalid object name 'Branch'." The code is found below: Help me pls! Thank you. Private Sub...
8
by: Shelly | last post by:
I get an error that the input string is not in the right format. Here is the result: Here is the partial code: Dim sqlConn As New SqlConnection(SqlDataSource1.ConnectionString) Dim query As...
11
by: James R. Davis | last post by:
Yes, a newbie here. Though I am making progress, slowly, I am also getting more and more confused. With ASP, when I wanted to do something as trivial as updating a visitor counter, I...
4
by: =?Utf-8?B?VG9kZCBKYXNwZXJz?= | last post by:
Here is what I have: private int NationalCount() { Int32 numRecords = 0; using (SqlConnection dataConnection = new SqlConnection(GlobalVars.sqlConnString)) { SqlCommand dataCommand = new...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.