After doing more reading and research into managing data, I have redone the code based off the MSDN site for a dataset; however, I am running into a snag. I believe I have declared the dataset within a class-level; however, whenever I attempt to pull that dataset with
DataRow[] drRow = tblEmployee.Select("EmployeeKey = " + TextBox12.Text)
I am getting the errors:
- The name 'tblEmployees' does not exist in the current context
- The name 'TextBox12' does not exist in the current context
I want to be able to declare it at the class level so I can call it from anywhere within the form.
I have already read through the MSDN site on class levels, and honestly I think that has just confused me to a greater degree.
Basically is what I want to happen is dataset provides a list of employees in alphabitical order by first name, then when a user selects the the employee from drop down box, it should select the employee ID and display it in textBox12, then perform a search of the tblEmplpoyees for the remaining data to display for the employee such as fields defined in //comments in the code.
Can someone assist me with this, here is what I have for code atm:
namespace Tempus.Menus
{
public partial class Employees : Form
{
public class myData
{
DataSet[]drRow = tblEmployees.Select("EmployeeKey = " + TextBox12.Text);;
}
public Employees()
{
InitializeComponent();
//Connect to database for Employees Table Headers
SqlConnection myConnection = new SqlConnection(@"Server=server\CHCTEMPUS;Integrated Security=true;" +
"user id=userID;password=password;" +
"Trusted_Connection=yes;" +
"Database=Database;" +
"connection timeout=30");
SqlDataAdapter daEmployees
= new SqlDataAdapter("Select *, Lname +', '+ Fname as LastFirst, Fname +' '+ Lname as FirstLast FROM Employees WHERE Lname IS NOT NULL AND Fname IS NOT NULL", myConnection);
DataSet dsEmployees = new DataSet("Employees");
daEmployees.FillSchema(dsEmployees, SchemaType.Source, "Employees");
daEmployees.Fill(dsEmployees, "Employees");
DataTable tblEmployees;
tblEmployees = dsEmployees.Tables["Employees"];
comboBox1.DisplayMember = "FirstLast";
comboBox1.ValueMember = "employeeNumber";
comboBox1.DataSource = tblEmployees;
try
{ }
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
if (myConnection != null)
{
myConnection.Dispose();
}
}
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
comboBox2.SelectedIndexChanged += comboBox2_SelectedIndexChanged;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex != -1)
{
textBox1.Text = string.Empty;
}
{
textBox12.Text = comboBox1.SelectedValue.ToString();
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedIndex == -1)
{
textBox1.Text = string.Empty;
}
else
{
textBox1.Text = comboBox2.SelectedItem.ToString();
}
}
private void Employees_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
//Last Name
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
//First Name
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
//Middle Name
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
//Hire Date
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
//Term Date
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
//Company
}
private void textBox7_TextChanged(object sender, EventArgs e)
{
//Notes
}
private void textBox8_TextChanged(object sender, EventArgs e)
{
//PTO
}
private void textBox9_TextChanged(object sender, EventArgs e)
{
//SNP
}
private void textBox10_TextChanged(object sender, EventArgs e)
{
//Credentials
}
private void textBox11_TextChanged(object sender, EventArgs e)
{
//Employee Full Name (First Last)
}
private void textBox12_TextChanged(object sender, EventArgs e)
{
//Employee ID
}
private void textBox13_TextChanged(object sender, EventArgs e)
{
//Branch
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
// logic here for if the box has now been checked
}
else
{
// what to do if the box has been unchecked
}
}
private void button1_Click(object sender, EventArgs e)
{
Main myNewForm = new Main();
myNewForm.Show();
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
Reports myNewForm = new Reports();
myNewForm.Show();
this.Close();
}
}
}