Question Name does not exist in current context

kwhelchel

Well-known member
Joined
Feb 28, 2020
Messages
53
Programming Experience
Beginner
Having problem with a setup and can not figure this one out.
Line 53 is stumping me with this.

dashboard:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace Reporting_v1
{
    public partial class DashBoard : Form
    {
        List<Closeout> closeout = new List<Closeout>();
        public DashBoard()
        {
            InitializeComponent();

            UpdateBinding();
        }
        private void UpdateBinding()
        {
            filterListBox.DataSource = closeout;
            filterListBox.DisplayMember = "FullCloseout";
        }

        private void viewrptbtn_Click(object sender, EventArgs e)
        {
            switch (reportListBox.SelectedItem.ToString())
            {
                case "DSR":
                    DSR h = new DSR();
                    h.ShowDialog();
                    break;

            }

        }

        private void reportListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
    

        }

        private void closeoutlbl_Click(object sender, EventArgs e)
        {
            DataAccess db = new DataAccess();

            closeout = db.GetCloseout(closeidText.Text);

            UpdateBinding();
        }

        private void filterListBox_SelectedIndexChanged(object sender, EventArgs e)
        {

;
        }

        private void closeouttextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void DashBoard_Load(object sender, EventArgs e)
        {

        }
    }
}
 
Here is the data access and I will look at the info you posted too

Dataaccess:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Data;


namespace Reporting_v1
{
    class DataAccess
    {
        public List<Closeout> GetCloseout(string closeid)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("versiposdb")))
            {
                //var output = connection.Query<Person>($"select * from People where LastName = '{ lastName }'").ToList();
                var output = connection.Query<Closeout>("dbo.spCloseout_GetAll @closeid", new { Closeid = closeid }).ToList();
                return output;
            }
        }

    }
}
 
Are you sure you have a textbox control named closeidText?
Bingo.

@kwhelchel, I had to check for myself. But I believe the reported error is significantly different to that being reported by access modifier issue.

Apologies for misleading you, that doesn't happen very often. You should double check the name of your textbox control. But note, you should also make sure you always specify an access modifier on your methods, classes and properties, so those docs I linked are still worth reading. And also add the approperiate access modifier for the scope you want your DataAccess class to have.

Screenshot_92.jpg


Notice the IDE is complaining about the name of the object not existing. That is because it doesn't exist in my case.

That's where my fire hose approach got me. :LOL:

If you have loads of controls, you can search like this to save time :
C#:
Debug.WriteLine($"Control Exists : {Controls.Find("closeidText", true)[0].Name}");
 
Last edited:
For future reference, please only post RELEVANT code. Everything that you post that isn't relevant just makes it harder for us to read and thus less likely that you'll get the help you need. You have numerous empty methods in that code so it's rather likely that they, at least are not relevant to the problem.
 
Back
Top Bottom