Friday, March 23, 2012
It is possible with cursor?
A want to use a Select sprocs (for re-use de code), but this sproc return 15 columns and the 3 a need was not the 3 frist. :confused:
Do I need to map the 15 columns with 15 variables locally? Or they have a way easier?
Thankscan u post the code? some one here might come up with a better solution|||DECLARE cuTEST CURSOR FOR
ItemsSEL
OPEN cuTEST
FETCH NEXT FROM cuTEST
INTO @.col1, @.col2, @.col3, @.col4, @.col5,....
but I need only col2, col10 and col14
ItemsSEL is my Strore Procedure for my complexe Select Use many place in my application ( where a need all result columns...)|||Would it be possible to redesign the ItemsSel procedure into a view? How complex is this procedure?
Monday, March 19, 2012
Issues with an output param from a sproc using SQLDataSource
I have a stored proc that I'd like to return an output param from. I'm using a SQLDataSource and invoking the Update method which calls the sproc.
The proc looks like this currently:ALTERproc [dbo].[k_sp_Load_IMIS_to_POP_x]
@.vcOutputMsgvarchar(255)OUTPUTAS
SETNOCOUNTON;
select @.vcOutputMsg='asdf'
The code behind looks like this:
protectedvoid SqlDataSource1_Updated(object sender,SqlDataSourceStatusEventArgs e){
//handle error on return
string returnmessage = (string)e.Command.Parameters["@.vcOutputMsg"].Value;
}
On the page source side, the params are defined declaratively:
<UpdateParameters>
<asp:ParameterDirection="ReturnValue"Name="RETURN_VALUE"Type="Int32"/>
<asp:ParameterDirection="InputOutput"Name="vcOutputMsg"Type="String"/>
</UpdateParameters>
When I run it, the code behind throws the following exception - "Unable to cast object of type 'System.DBNull' to type 'System.String'"
PLEASE HELP! What am I doing wrong? Is there a better way to get output from a stored proc?
I got mine to work. Here's my example.
ASPX
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" autogenerateeditbutton="true"datasourceid="SqlDataSource1"><columns><asp:boundfield datafield="ShipperID" headertext="ShipperID" readonly="True" /><asp:boundfield datafield="CompanyName" headertext="CompanyName" readonly="True" /><asp:boundfield datafield="Phone" headertext="Phone" readonly="True" /></columns></asp:gridview><asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString%>"onupdated="SqlDataSource1_Updated" selectcommand="SELECT * FROM [Shippers]" updatecommand="sp_GetMessage"updatecommandtype="StoredProcedure"><updateparameters><asp:parameter direction="InputOutput" name="Message" size="50" type="String" /></updateparameters></asp:sqldatasource><asp:label id="Label1" runat="server" />
CODE-BEHIND
protected void SqlDataSource1_Updated(object sender, SqlDataSourceStatusEventArgs e){Label1.Text = e.Command.Parameters["@.Message"].Value.ToString();}STORED PROCEDURE
ALTER PROCEDURE dbo.sp_GetMessage(@.MessageAS VARCHAR(50)OUTPUT)ASBEGINSELECT @.Message ='Hello World!'END|||
Mine looked identical to yours except for the size on the output param. Once I added it in, it worked beautifully!! Not sure why it wasn't automatically declared when I configged the SQLDatasource to use the update method. But hey, it works now!!!
Thanks for the help!!!!!
Bill
|||Mine didn't get created either, except I got another error actually referencing the absence of a size. I'm not too sure why you didn't receive the same. I also don't know why the Size attribute is needed.