Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8382343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:54:36+00:00 2026-06-09T16:54:36+00:00

I’m currently trying to populate a datagrid using a member of a class that

  • 0

I’m currently trying to populate a datagrid using a member of a class that uses SQLCommand to execute a stored procedure and return the results.

My class member (and where I believe the issues lies) is:

public DataView DisplayHealthIndicator(DateTime startDate, DateTime endDate)
{
    string queryString =
        "DECLARE @RC int"
        + "DECLARE @date_from datetime = dateadd(day, 0, datediff(day, 0, getdate()))"
        + "DECLARE @date_to datetime = dateadd(day, 0, datediff(day, 0, getdate()))"

        + "EXECUTE @RC = [Testing].[marlin].[support_retrieve_workflow_history] "
            + "@date_from "
            + ",@date_to"
        + "GO";

    using (SqlConnection connection = new SqlConnection(GetConnectionString()))
    {
        using (var cmd = new SqlCommand(queryString, connection))
        {
            connection.Open();

            var reader = cmd.ExecuteReader();

            var dt = new DataTable();
            dt.Load(reader);

            return dt.DefaultView;
        }
    }

}

and I’m calling this member using:

var db = new DatabaseHandle();
        dataGridWorkflow.ItemsSource = db.DisplayHealthIndicator(DateTime.Now, DateTime.Now);

However! I’m currently receiving the error:

Incorrect syntax near @date_from

Must declare the scalar variable @RC

To a degree I understand the error – I believe that I can’t declare variables in my sqlQuery string… but then, how do I do this?

I’m fairly sure that it doesn’t have any bearing on this, but in case it does, this is the contents of the stored procedure:

create procedure marlin.support_retrieve_workflow_history
(
    @date_from datetime,
    @date_to datetime
)
as
select  dateadd(day, 0, datediff(day, 0, e.event_date)) as 'Date',
        c.setting_secondary 'Workflow Category' ,
        d.setting_main as 'Error Type' ,
        sum(e.event_count) as 'Total'
from    marlin.support_events e
        inner join marlin.support_config c
            on e.event_category = c.setting_code
            and c.config_code = 60
        inner join marlin.support_config d
            on e.event_type = d.setting_code
            and d.config_code = 70
where   e.event_date between @date_from and @date_to
group by 
        e.event_date,
        c.setting_secondary ,
        d.setting_main
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:54:37+00:00Added an answer on June 9, 2026 at 4:54 pm

    cmd.Parameters["@ReturnValue"] contains the return value – you don’t need to add a parameter in dynamic SQL

    Add your parameters to the cmd

    cmd.Parameters.AddWithValue("ParamName", Value);
    

    Also change the cmd.CommandType (might not be called that, check members of cmd) to StoredProcedure

    e.g.

    using (SqlConnection connection = new SqlConnection(GetConnectionString()))
    {
        using (var cmd = new SqlCommand(queryString, connection))
        {
            connection.Open();
    
            cmd.CommandType = ??.StoredProcedure; // Can't remember what enum name is prob SqlCommandType or something
            cmd.Parameters.AddWithValue("date_from", DateTime.blah.blah);
            cmd.Parameters.AddWithValue("date_to", DateTime.blah.blah);
            var reader = cmd.ExecuteReader();
    
            var dt = new DataTable();
            dt.Load(reader);
    
            return dt.DefaultView;
        }
    }
    

    Disclaimer: Some of these prop names, the name of the return value param might not be correct so check the docs 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.