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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:32:58+00:00 2026-06-14T13:32:58+00:00

I have the design, framework, and most of the code finished for an inhouse

  • 0

I have the design, framework, and most of the code finished for an inhouse application I have created. I am attempting to add some functionality, which will translate into 3 completely different forms, that access, view, and update data stored on an Access Database, placed on a hidden network drive.

The relevant information for the question I have is as follows…
1) User launches application which then collects and displays their current logged in username, and asks them if they wish to procede.
2) Once they choose to procede, the code searches an Agent table in the MS Access Database to see if there is a record created for the agent’s name.
3) If the record exists (currently) the form will close, returning to a data entry form to begin inputing information only displaying their username
4) If the record does NOT exist, it open another form, where the user will enter their details, manager, shift start and end time, and their AgentID
5) Once the Agent details are saved, then the application returns to the data entry form to begin inputing information.

What I wish to accomplish with this code…
In step 3), after successfully finding a record that matches their username, return a value from the matching row, in the AgentID column. The database has a lookup field that matches AgentID to their specific role, which I will use later to show an altername form based on the user’s role. For now, I only wish to get the AgentID from the corresponding row, then save the value to a static class variable I created to be utilized by other existing forms.

The using statements for reference

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Security.Principal;

The code I want to figure out is within the If function. The code will successfully identify if the user has an entry in the Agent table, and if not, send the user to a form to create the entry.

private void button1_Click(object sender, EventArgs e)
    {
        // set FNameLabel to user's name without domain
        FNameLabel.Text = WindowsIdentity.GetCurrent().Name.Split('\\')[1];
        // create OleDb connection and command, @name for agent name variable
        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.jet.oledb.4.0;data source=\\myserver\hidden$\database.mdb");
        OleDbCommand cmd = new OleDbCommand("SELECT * FROM Agent WHERE AgentName=@name");
        // create command connection and set parameters
        cmd.Connection = con;
        cmd.Parameters.AddWithValue("@name", FNameLabel.Text);
        con.Open();
        OleDbDataReader read = cmd.ExecuteReader();
        // If there is a record that matches Agent Name, return to previous form
        if (read.Read() == true)
        {
            // MessageBox.Show("agent name in database");

            // If Agent Name matches, return Agent ID, passed to custom class variable
            // Class variable for Agent ID
            // AgentID.Var = [some variable that contains AgentID where AgentName = current user]
            this.Close();
            return;

        }
        // If there is no record that matches Agent Name, open form to enter Agent details
        // MessageBox.Show("agent name NOT in database");
        AgentInfo agents = new AgentInfo();
        agents.ShowDialog();
        this.Close();



    }

The class variable works without a hitch

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataEntry
{
static class AgentID
{
    private static string agentid = "";

    public static string Var
    {
        get 
        { 
            return agentid; 
        }
        set 
        { 
            agentid = value; 
        }
    }
}

}

  • 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-14T13:33:02+00:00Added an answer on June 14, 2026 at 1:33 pm

    I ended up solving this issue by adding 1 line of code and changing my SELECT statement

    OleDbCommand cmd = new OleDbCommand("SELECT AgentName, AgentID FROM Agent WHERE AgentName=@name");
    

    I then added this line within the If function

    AgentID.Var = read[1].ToString();
    

    By changing the * to the two columns I wanted (AgentName & AgentID) it assigned them to columns 0 and 1. The AgentName in column 0 and the AgentID in column 1. I then simply took my custom variable and assigned the value of what was read from column 1, after it came back true (read[1]) nested in the if (read.Read() == true). I also made certain to assign the value, even though in this case it is a number, to string to pass to my string variable class.

    The result, I can now make a call to my AgentID class, and retrieve the value assigned with the .Var anywhere in My application at any time regardless of which form is open.

    2 Thumbs Up 🙂

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

Sidebar

Related Questions

I have an n-tier application design problem with Entity Framework 4. Server-side, my application
I have a design question. We need to put some default, system defined content
I have this design which I cannot seem to get right, I would like
I've written an application that handles most exceptions gracefully, with the page's design intact
I have looked at some of the info on cross platform design. I can't
I have been trying to get JQuery Sortable working on my Zend Framework application
I have to design a GUI using Qt. I would like to draw multiple
I have a design problem: I have two threads, a heartbeat/control thread and a
I have a design problem: Question class: have a question and answer (String) TextQuestion
We have a design we need to implement where the concept is the user

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.