This is a migrated thread and some comments may be shown as answers.

Getting results to display via a stored procedure

2 Answers 212 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 2
Bill asked on 21 Jan 2013, 10:48 PM
I need to display results in a RadGrid from the selected parameters inside a report viewer via a stored procedure.

Can someone please brifely explain how I can accomplish this based on the below stored procedure: The 4 parameters in the report viewer are selected and used in the stored procedure below:
ALTER PROCEDURE [dbo].[SelectProductInfoByShipAndDate]
    @CruiseLine nvarchar(max),
    @Ship nvarchar(max),
    @FromDate date,
    @ToDate date
AS
BEGIN
    SET NOCOUNT ON;
    Select *
        FROM dbo.Daily_Totals
        WHERE CruiseLine IN (SELECT * FROM dbo.SplitParameterValues(@CruiseLine, ','))
          AND Ship IN (SELECT * FROM dbo.SplitParameterValues(@Ship, ','))
          AND [Date] BETWEEN @FromDate AND @ToDate
         ORDER BY CruiseLine, Ship, [Date], Product1Cash, Product2Cash, Product3Cash, Product4Cash, Product5Cash, Product6Cash, Sales
END

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Jan 2013, 05:14 AM
Hi,

You can bind the RadGrid with the Stored Procedure result in the NeedDataSource event of the RadGrid. Please check the following code snippet I tried.

C#:
public static string connection = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString3"].ConnectionString;
SqlConnection conn = new SqlConnection(connection);
public SqlCommand cmd = new SqlCommand();
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    cmd.Connection = conn;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@Parameter1",10259);
    cmd.Parameters.AddWithValue("@Parameter2", 4);
    cmd.CommandText = "StoredProcedureName";
 
    DataSet dt = new DataSet();
    SqlDataAdapter adp = new SqlDataAdapter();
    adp.SelectCommand = cmd;
    adp.Fill(dt);
    RadGrid1.DataSource = dt;
    conn.Close();
}

Thanks,
Shinu.
0
Kathryn
Top achievements
Rank 1
answered on 02 Oct 2018, 06:13 AM
Still doesn't work
Tags
Grid
Asked by
Bill
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Kathryn
Top achievements
Rank 1
Share this question
or