We help IT Professionals succeed at work.
Get Started

The name 'userFullName' does not exist in the current context

kalittaair
kalittaair asked
on
531 Views
Last Modified: 2013-11-07
Using VS 2008
C#
.NET 3.5

Getting the error in the title above. See the code below. How can I fix without calling my AD.getfullName method again in the buttonAuthorize_click event? I know my SQL statements are good because if I remove the offending one the other three pieces of data write correctly.

Thanks in advance.
private void main_Load(object sender, EventArgs e)
        {
            //Determine AD user name and full name. These are calls to a custom class I made and these calls work fine.
            string userName = AD.getuserName();
            string userFullName = AD.getfullName(userName);
            
            //Create collection for employee names
            StringCollection employees = new StringCollection();
 
            // userFullName shows up correctly here - so I know my variable is getting populated correctly.
            this.Text = "Crew Reserve Tracker: " + userFullName; 
 
            employees = MISA.getCrew();
                     
             foreach (String employee in employees)
            {
                crewBox.Items.Add(employee);
            }
        }
 
        private void buttonAuthorize_Click(object sender, EventArgs e)
        {
            int randomNumber = RandomNumber(10000, 99000);
            string crewName = crewBox.Text.ToString();
            DateTime now = DateTime.Now;
                       
            //Open connection to SQL DB
            SqlConnection conn =
            new SqlConnection("Data Source=SERVER;Initial Catalog=DB01;Integrated Security=True");
 
            conn.Open();
 
            string sqlInsert = "INSERT INTO Authorizations (Date, AuthNumber, CrewMember, Employee) values (@now, @randomNumber, @crewName, @userFullName)";
 
            SqlCommand sqlCom = new SqlCommand(sqlInsert, conn);
 
            sqlCom.Parameters.AddWithValue("@now", now);
            sqlCom.Parameters.AddWithValue("@randomNumber", randomNumber);
            sqlCom.Parameters.AddWithValue("@crewName", crewName);
            //ERROR OCURS ON THIS LINE 
            sqlCom.Parameters.AddWithValue("@userFullName", userFullName);
 
            sqlCom.ExecuteNonQuery();
            sqlCom.Dispose();
 
            conn.Close();

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 19 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE