.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

does sp_executesql output return more than one record

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :Sql Server
Does sp_executesql return more than one row outputs.
 I am having a issue with it: 

my code is supposed to return 2 rows in the output but it is returning onyl one row(second row).
I guess, the first one is being overwritten by the second one. I am using sp_executesql because the sql string is being dynamically built.

the output is supposed to be like 
sno sname
 1   clay
 2   teri
instead it is showing like this 
sno sname
 2   teri

any idea on this?

View Complete Post

More Related Resource Links

Enterprize library 4.1 getting output parameter after adding record in db, plz guide



I need to get output parameter (flag) from db after saving record in database. I am using Microsoft Enterprise Library 4.1 for DB. I am inserting record using I Data reader.

Please guide


[newbie] How to return a data record from a webservice (wsdl)?



vs2010, .NET 4.0

I have a webmethod which I want to return a data record (for example: name, surename, address, age, zip etc)

I wonder how to accomplish this. I think the solution is about creating an object which contains all the records serialized. And then the webmethod returns this serialized object. I'm not 100% sure how to accomplish this, if some of you good provide me with some tips, tutorial or link to an article explaining it, that would be great

How to return a specific field from the last record entered


I have two tables, Discrepancies and Actions that are linked by a field called JobNumber

What I need to do in a stored procedure is return a date field from the last record entered in the Actions table where the JobNumber is the same

The Actions tables primary key is an Identity field.

I'm trying to make a subquery but am stuck on the syntax.

Any help would be appreciated, this is just a bit beyond my skill set. Thanks.

Running a WPF application from a console app and return status/console output from the wpf


I am trying to run a WPF application from a console application (e.g. a .bat file) but need to be able to receive console and error output from the WPF application.

I have console.writeline() and console.error.writeline commands in the WPF application but these are not received by the console application.

I would also like to receive a status value from the WPF on completion.

Is this possible?

If so could you give me a simple example using VB?

How to return looped procedure results so that they display as multiple rows of a single output inst


I understand that the below fragment will return a separate 1-row results set for each successful loop (also unnecessarily repeating the column header each time). How can I alter my procedure so that each value returned by the loop is appended underneath the previous value as multiple rows of a single results set? Do I have to store each return value in a temp table or someother storage object? It would be nice to just be able to spit them out row by row as each loop returned. Possible? Easy? Hard? I really appreciate the help I've received here so far.

SELECT (whatever)

OPEN techCursor;
FETCH NEXT FROM techCursor INTO @techNumLoop;
EXECUTE pr_FindExpenses4Tech @techNumLoop, @itemCount OUTPUT
SELECT @itemCount Item_Count

Stored Procedure, when to use Output paramemter vs Return variable


When would you use an output parameter vs a return variable, or vice versa? In the following simple example, I can achieve the samething using either one.

Using output parameter

create proc dbo.TestOutput (@InValue int, @OutValue int output)
set @OutValue = @InValue

declare @x int
exec TestOutput @InValue = 3, @OutValue = @x output
select @x


Using return variable:

create proc dbo.TestReturn (@InValue int)
return @InValue

declare @x int
exec @x = TestReturn @InValue = 3
select @x


As you can see, they both do the samething. Can someone show me an example where the choice of a output parameter vs a return variable would make a difference?

How to get total record count in an OUTPUT Parameter


I couldn't get the total record count in a, in my stored proc, in a given scenario. Please help


My SP looks like this:

create proc RecordCount

       @CustomerID varchar(10),

       @RecCnt int OUTPUT


begin tran

if(CustomerID = 'ABC')

@RecCnt = select count(*) from Customers where CustomerID='ABC'



begin tran


@RecCnt = select count(*) from Customers where CustomerID='XYZ' and TranDate > '05/01/2009'




-- This is how I called my SP

declare @rc int

exec RecordCount 'XYZ', @RecCnt = @rc OUTPUT

select @rc

I have my insert logic in my class, how do i output the return value on my page to use with another


I have the following portion in my class, i need to get the value of the inserted record so i can use in another insert that im doing with a loop, so i need to add another variable to my

"public void insertServ( string EmLogin, string EmPass, int Emnum )"  the procedure is already returning the value i need, just need to get it back on the page so i can use it with my next insert.



                cmd.Parameters.Add("@EmLogin", System.Data.SqlDbType.VarChar).Value = EmLogin;
                cmd.Parameters.Add("@EmPass", System.Data.SqlDbType.VarChar).Value = EmPass;
                cmd.Parameters.Add("@EmNum", System.Data.SqlDbType.Int).Value = EmNum;

                cmd.Parameters["id"].Direction = ParameterDirection.ReturnValue;

            catch (System.Data.SqlClient.SqlException ex)
                string msg = "Server Email Insert Error:";
                msg += ex.Message;
                throw new Exception(msg);


How to create a View to return all multiple child fields in one record?


I have an application where the users can define up to 5 extra fields for a particular table (e.g. tblMaster). The custom data is all held in one table (e.g. tblCustom) so there could be up to 5 records in tblCustom for each tblMaster record. In my application I build a select statement based on the number of custom fields so that I can get a single row of data for each tblMaster record (sample below). I am now adding new features to the application and I want to expose an SQL View to the users for a report writer that will achieve the same result but still cater for the variable number of custom fields. I realise this needs to use probably a RIGHT OUTER JOIN so that NULL is returned if there is no matching field but I can't work it out. If I had five separate files it would be easy as each one would be a RIGHT OUTER JOIN for each. I could build 6 views (e.g. with no custom fields, with one custom field, with two custom fields etc) but that is not very efficient. I don't particulaly want to restructure the database as there would be a lot of work and retesting.
Any help would be very welcome!

SELECT tblProcess.ProcessNumber, tblProcess.Process, tblProcess.Risk, tblProcess.MRR, tblProcess.Version, tblProcess.LastChange, tblProcess.SecurityLevel, 

GridView inline Master/Detail record display

This code drop is part of a smash and grab series. If you're in a rush, you can just grab this code and insert it into your application, no understanding is required. When you have some time (ya, right) you may want to review the source code.

Comma-Delimited Output

One of the common tasks performed when retrieving data from a SQL Server database is returning the result as a comma-delimited output instead of a result set. This task can be performed by using a CURSOR selecting the column to be concatenated together. Each row returned by the CURSOR is then concatenated together into a variable separating each one by a comma.

Get Top 1 Record from Dataset

Many of them in need of getting the Top 1 or Top 10 records from a Dataset without going to SQL query. It is possible to do from Code Behind. I have given the code below,
The below code is to get single record from a Dataset. Also I have given for getting 8 records at Green Color.

Gridview Edit on Searching of Record


using Asp.net c#

sql server

i am searching a record from my database and displaying it in gridview now i want the comments should be updated as per the record which is being searched

For E.g if record No.3 is searched then only i can update record no.3 and i don't want rest of data to be shown

now what is happening when i click on edit my whole table is being displayed

this is bcuz i made one method gridfill() which i m calling everytime if i m doing grid row editing,row cancelling and row updating

how i can resolve this thing

my code

 protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
        GridView2.EditIndex = e.NewEditIndex;


 protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
        string id = GridView2.Rows[e.RowIndex].Cells[0].Text;
        TextBox t;
        t = (TextBox)GridView2.Rows[e.RowIndex].Cells[2].Controls[0];
        string query = "update user1 set comments=@comments where id=@id";
        SqlConnection con = new SqlConnection(connstr);
        SqlCommand cmd = new SqlCommand(query, con);

ListView DataPager with SQL-Statements that already return only paged data.



As far as I understand the ListView-Control and the DataPager-Control, they work like this: The ListView gets its datarows from its data source, then the DataPager causes the ListView to display only a subset of those rows.

So what, when I want to use custom databinding for the ListView, that *already* gets the certain subset from SQL-Server (for better performance). Can I and how can I use the DataPager then?

Thanx, S.

Does this look correct for saving a file/ new record to a database


So thank you for all your help so far, So I think i got this right,
but would like for you all to look it over to see if there is any
areas I might run into trouble with:

//using asp.net mvc 2
the table (sql server 2005, using entities framework)
table fields
"Pattern_Media_GUID  uniqueid 
"Pattern_GUID  uniqueid
"Media varbinary(max)  
"height int
"Width int
"Media_Type String (50)

the form:
<h2> Add Media to this pattern</h2>
<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
    <%: Html.Label("height") %>
    <%: Html.TextBox("height") %>

    <%: Html.Label("width") %>
    <%: Html.TextBox("width") %>

    <%: Html.Label("Media") %>
    <input type="file" id="Media" name="Media" />
    <input type="submit" name=

Inline conditional output


Is it possible to somehow output some content based upon some conditional check in Razor? If not, I hope this possibility will be added in the future. What I want to do is the following:

<option value="1" @if(ListMode == 1) { = "selected=\"true\"" }>Full list</option>

As I can't figure out a way to do this, I have to either make a helper that does it for me or write duplicate code.

Why show only one record?



// Update these variables to values whatever you are storing in your table
        // If you are storing as CARD NUMBER, update this Card Number Attribute Name to CARD NUMBER
        string strCardNumberAttributeName = "Credit card number";
       // string strCardTypeAttributeName = "1";
        string strExpiryDateAttributeName = "Expiry date";
        DataTable dtPaymentDetails = new DataTable();

        string queryString = "SELECT tbl_Payments.PaymentId, tbl_PaymentDetails.AttributeName, tbl_PaymentDetails.Value, tbl_Payments.PaymentType FROM tbl_Payments INNER JOIN tbl_PaymentDetails ON tbl_Payments.ID = tbl_PaymentDetails.PaymentId WHERE ATTRIBUTENAME IN ('" + strCardNumberAttributeName +
                                   "','" + strExpiryDateAttributeName + "') ORDER BY PaymentId";

        string connectionString = "data source=.\\SQLEXPRESS;Integrated Security=SSPI;" +
                                           "AttachDBFilename=|DataDirectory|\\BurnbetDatabase.mdf;User Instance=true";
        using (SqlConnection connection = new SqlConnection(connectionString))
            SqlCommand command = new SqlCommand(queryString, connection);
            SqlDataReader reader = command.ExecuteR
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend