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

  • Home
  • SEARCH
  • 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 6689529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:31:48+00:00 2026-05-26T05:31:48+00:00

Hey I’m pretty new to c# and I’m sure that this isn’t too difficult

  • 0

Hey I’m pretty new to c# and I’m sure that this isn’t too difficult of an issue, however I cannot get my head around it.

I have a method in which I retrieve all of the variables from a windows form and submits them into another method that inserts them into the database. It works fine when the variables are declared however when I try and add in a bit of validation to check for null values I am recieveing a “the name ‘gridRef1V’ does not exist in the current context” error.

The validation I have at the minute is,

if (cbGridRef1.SelectedValue != null)
        {
            string gridRef1V = cbGridRef1.SelectedValue.ToString();
        }
        else
        {
            MessageBox.Show("The grid ref1 field must contain a value");
            cbGridRef1.Focus();
        }

The line of code that is recieveing the error message is,

SQLMethods.inspectionInsert(scrapTypeV, scrapShiftV, scrapDateV, prodAreaV, castDateV, dieNoV, dieCodeV, dieDescV, machineV, casterIDV, castShiftV, fettlerIDV, scrapCodeV, scrapTotalV, partIDV, gridRef1V, gridRef2V, qtyScrapV);

Thanks for any help 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-26T05:31:48+00:00Added an answer on May 26, 2026 at 5:31 am

    You have a scope error. Move

    string gridRef1V;
    

    To outside of the if statement.

    When you have it inside the if statement, the variable is not available outside of that code block.

        // gridRef1v doesn't exist
        if (cbGridRef1.SelectedValue != null)
        {
            string gridRef1V = cbGridRef1.SelectedValue.ToString();
        }  //gridRef1V no longer available after this } 
        else
        {
            // gridRef1v doesn't exist
            MessageBox.Show("The grid ref1 field must contain a value");
            cbGridRef1.Focus();
        }
        // gridRef1v doesn't exist
    

    What you want is something more like:

        string gridRef1v;
        if (cbGridRef1.SelectedValue != null)
        {
           gridRef1V = cbGridRef1.SelectedValue.ToString();
        }  //gridRef1V still available after this } 
        else
        {
            // gridRef1v exists
            MessageBox.Show("The grid ref1 field must contain a value");
            cbGridRef1.Focus();
        }
        // gridRef1v exists
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey so I cannot seem to get Facebook, OmniAuth, Rails, and Heroku to play
Hey i have been looking around and i cant find a way to get
Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
hey guys having this really simple problem but cant seem to figure out have
Hey all i have a JSFiddle that i have been working on with trying
Hey I have following code like this public object RetrieveItemRun(int item) { if (dictionary.ContainsKey(item))
Hey guys I have an array of dictionaries plist file that I am reading
Hey I thought about writing a function that prompts me in certain situations (perl
Hey everyone I have a basic search function here that allows me to search
Hey i am new to iOS development, in my app i want to fetch

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.