Hi every experts
I have a exist Stored Procedure in SQL 2005 Server, the stored procedure contain few output parameter, I have no problem to get result from output parameter to display using label control by using SqlCommand in Visual Studio 2003. Now new in Visual Studio 2005, I can't use sqlcommand wizard anymore, therefore I try to use the new sqldatasource control. When I Configure Datasource in Sqldatasource wizard, I assign select field using exist stored procedure, the wizard control return all parameter in the list with auto assign the direction type(input/ouput...), after that, whatever I try, I click on Test Query Button at last part, I always get error messageThe Query did not return any data table.
My Question is How can I setup sqldatasource to access Stored Procedure which contain output parameter, and after that How can I assign the output parameter value to bind to the label control's Text field to show on web?
Thanks anyone, who can give me any advice.
Satoshi
Here's an example for you:
ASPX
<asp:label id="Label1" runat="server" /><asp:gridview id="GridView1" runat="server" datakeynames="ProductID" datasourceid="SqlDataSource1"></asp:gridview><asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString%>"onselected="SqlDataSource1_Selected" selectcommand="SELECT * FROM [Products]; SELECT @.count = COUNT(*) FROM [Products];"><selectparameters><asp:parameter direction="Output" name="count" type="int32" /></selectparameters></asp:sqldatasource>
CODE-BEHIND
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e){if (e.Exception ==null){Label1.Text = String.Concat("Records returned:", e.Command.Parameters["@.count"].Value);}}|||
Hi ecbruck
Thanks very much your help, I'm able to make it work now.
No comments:
Post a Comment