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 6161291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:27:13+00:00 2026-05-23T21:27:13+00:00

I have to Declare a SqlParameter[]. It’s size is dynamic based on the dropdownlist

  • 0

I have to Declare a SqlParameter[].
It’s size is dynamic based on the dropdownlist selection.
I have implemented a method as below

protected void BindGrid()
{
    SqlParameter[] sqlparam;
    string SP = string.Empty;

    if (ddlKPIType.SelectedIndex == 0)//For Overall
    {
        sqlparam = PrepareSqlParams();

    }
    else if (ddlKPIType.SelectedIndex == 1)//For Parameterwise
    {
        sqlparam = PrepareSqlParamsForParameterWise();

    }
    else if (ddlKPIType.SelectedIndex == 2)//For Measurement Criteria wise
    {
        sqlparam = PrepareSqlParamsForMeasurmentCriteriaWise();

    }


    DataSet dsReport = GetReportDataSet(sqlparam, SP);

    if (isDataSetValid(dsReport))
        gridMonthlyReport.DataSource = dsReport.Tables[0];
    gridMonthlyReport.DataBind();

}

But in this code when I pass the sqlparam as a Parameter to GetReportDataSet() it is showing the error”Use of unassigned local variable ‘sqlparam’.

The methods :PrepareSqlParams()
,
PrepareSqlParamsForParameterWise() and
PrepareSqlParamsForMeasurmentCriteriaWise()
will return SqlParameter[].

Where I am making a mistake?
Any one please help me.
Thanks in advance.

  • 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-05-23T21:27:14+00:00Added an answer on May 23, 2026 at 9:27 pm

    sqlparam is not guaranteed to be assigned, because there is no else clause. If ddlKPIType.SelectedIndex is 3 or greater, sqlparam will not be assigned, because none of the branches of your if-else if clause will be executed.
    You can overcome this in several ways:

    1. If you are sure, that it can never be 3 or greater, insert an else clause that throws an ArgumentOutOfRangeException
    2. If you are not sure that it can never be 3 or greater, just initialize sqlparam.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C#, if I declare an auto-implemented property, why do I have to declare
I have a question What happend when I declare a variable inside a method,
I have a query like below declare @str_CustomerID int Insert into IMDECONP38.[Customer].dbo.CustomerMaster ( CustomerName
Why does the derived class have to declare its methods as virtual for dynamic
If I have a method declared like this: private void someFunction(object[] param1) When I
I have this code: dojo.declare(City, null, { constructor : function(cityid, cityinfo){ } }); dojo.declare(TPolyline,
I have a stored procedure DECLARE cursor FOR SELECT [FooData] From [FooTable]; OPEN cursor
I have a simple C function which I declare as: int strLen(const char* str_)
I have objects with many variables that I declare and explain in the comments.
I have a sql query as follows: Declare @DivisionNo INT SET @DivisionNo = 5117

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.