Get the name of a ComboBox in ComboBoxColumn - c#

I came across the following problem:
I have a DataGridView with 5 Column where the first 3 are ComboBoxColumns. So i want that a User has to select the first ComboBox so that on the second will be loaded the data (SQL Query with value of first ComboBox). An so on also for the third one which is only working when the first two are set.
Now i have the problem. If I check if selected Index change via the code below. It gives an error because on the second ComboBox i dont need .SubString(). So i wanted to check the names of the ComboBoxes and make some if branches to check wether is the first, second or third ComboBox. But all of my tries give me an empty return.
Is there a possibility to solve my problem?
private void datagridview1_detailed_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged += new EventHandler(selectionchange);
}
}
void selectionchange(object sender, EventArgs e)
{
try
{
ComboBox cb = (ComboBox)sender;
//To Test the output
Console.WriteLine("CB_NAME:" + ((ComboBox)sender).Tag);
Console.WriteLine("CB_NAME:" + ((ComboBox)sender).Name);
Console.WriteLine("CB_NAME:" + cb.Name);
if (cb.Name == "datagridview1_value1")
{
order_id = cb.Text.Substring(0, 6);
fill_second_combo();
}
else if (cb.Name == "datagridview1_value2")
{
fill_third_combo();
}
}
catch {
Console.WriteLine("Error");
}
}
Fill second ComboBox Code:
private void fill_second_combo()
{
string rcs = db_conn.connection();
using (var OraConn = new OracleConnection(rcs))
{
using (var OraCmd = OraConn.CreateCommand())
{
try
{
OraConn.Open();
OraCmd.BindByName = true;
OraCmd.CommandText = "select * from xxx where order_id" + order_id +";
OracleDataReader OraDataReader = OraCmd.ExecuteReader();
if (OraDataReader.Read() == false)
{
MessageBox.Show("No data!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
using (var OraDat = new OracleDataAdapter(OraCmd))
{
using (var combo2_table = new DataTable())
{
OraDat.Fill(combo2_table );
foreach (DataRow combo2_row in combo2_table .Rows)
{
foreach (DataColumn combo2 in combo2_table .Columns)
{
if (combo2_row[combo2 ] != null)
{
if (combo2.ColumnName == "Second Value")
{
secondComboBox.Items.Add(combo2_row[combo2.ColumnName].ToString());
}
}
}
}
}
}
}
}
catch (OracleException ex)
{
switch (ex.Number)
{
case 1:
MessageBox.Show("F1 -DB Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 12560:
MessageBox.Show("F2 - DB Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
default:
MessageBox.Show("F3 - DB Error: " + ex.Message.ToString(), "Fehlermeldung", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
OraConn.Dispose();
}
}
}
}
All of the Test-Outputs are empty in my case.

Related

(solved)IO exception The process cannot access the file because it is being used by another process

I'm trying to delete a line from a txt file with my program, but the program has the text file open so I can't. What do I do?
private void btnDeleteTransaction_Click(object sender, EventArgs e)
{
string line = null;
string delete = txtDeleteTransId.Text;
using (reader = new StreamReader(txtFilePath.Text))
{
try {
using (writer = new StreamWriter(txtFilePath.Text, true))
{
while ((line = reader.ReadLine()) != null)
{
if (String.Compare(line + "|", delete) == 0)
continue;
writer.WriteLine(line);
}
}
}
catch (Exception ex)
{
txtMessages.Text = "exception deleting transaction: " + ex.Message;
}
}
}
Figured it out below.
I'm dumb and was trying to write from the reader which you can't do. Here is my working code if anyone is as new as me.
private void btnDeleteTransaction_Click(object sender, EventArgs e)
{
List<string> records = new List<string>();
found = false;
using (reader = new StreamReader(txtFilePath.Text))
{
while (!reader.EndOfStream)
{
record = reader.ReadLine();
if (record.StartsWith(txtDeleteTransId.Text + "|"))
{
found = true;
}
else
{
records.Add(record);
}
}
if (!found)
{
txtMessages.Text = "Record ID was not found";
return;
}
}
try
{
using (writer = new StreamWriter(txtFilePath.Text, false))
{
foreach (var item in records)
{
writer.WriteLine(item);
}
}
txtMessages.Text = "Record deleted";
}
catch (Exception ex)
{
txtMessages.Text = "exception deleting record: " + ex.Message;
}
}
```

Filter not changing on backspace press - radgridview - C#

In my program I have a text box and on text change a filter is applied to my RadGrid. However, on backspace the filter is not reapplied.
private void txt_search_TextChanged_1(object sender, EventArgs e)
{
try
{
CompositeFilterDescriptor searchFilter = new CompositeFilterDescriptor();
searchFilter.FilterDescriptors.Add(new FilterDescriptor("product", FilterOperator.Contains, txt_search.Text));
this.radGridView1.EnableFiltering = true;
this.radGridView1.MasterTemplate.Templates[0].EnableFiltering = true;
this.radGridView1.MasterTemplate.Templates[0].ShowFilteringRow = false;
this.radGridView1.MasterTemplate.ShowFilteringRow = false;
this.radGridView1.MasterTemplate.Templates[0].ShowTotals = true;
this.radGridView1.MasterTemplate.Templates[0].ShowFilterCellOperatorText = false;
if (txt_search.Text != "")
{
this.radGridView1.MasterTemplate.Templates[0].FilterDescriptors.Add(searchFilter);
}
foreach (GridViewRowInfo row in radGridView1.MasterTemplate.Rows)
{
if (row.ChildRows.Count == 0)
{
row.IsVisible = false;
}
else
{
row.IsVisible = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Something went wrong searching the grid. Please try again and contact I.T. if this problem persists.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Is there another function which needs to be generated that is applied on backspace?
This code is taken from another program I have which is written in VB.net and converted. The filter works as it should in the VB version and is reapplied when text is removed etc.
Any help appreciated.

Get Highest and lowest value in input textbox and place value result textbox

I'm trying to get the Runner Time from the text box and place the results in the result textbox in descending order. The order should be 1st place, 2nd place, and 3rd place. I've tried using conditional statements but seems like I will have to use alot of code. Is there another way to figure out how to determine the 1st place, 2nd place and 3rd place.. Here is my code.
namespace Calculate Runner Time
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Calculatebutton_Click(object sender, EventArgs e)
{
string Runner1Name;
string Runner2Name;
string Runner3Name;
double Runner1Time;
double Runner2Time;
double Runner3Time;
//double FirstPlace;
//double SecondPlace;
//double ThirdPlace;
//get runner names
Runner1Name = Runner1NametextBox.Text;
Runner2Name = Runner2NametextBox.Text;
Runner3Name = Runner3NametextBox.Text;
//check if Runner1Name is empty
if (string.IsNullOrEmpty(Runner1Name))
{
MessageBox.Show("The Runner 1 Name cannot be empty ", "Invalid Runner Name",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//check if Runner1Name is empty
else if (string.IsNullOrEmpty(Runner2Name))
{
MessageBox.Show("The Runner 2 Name cannot be empty ", "Invalid Runner Name",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (string.IsNullOrEmpty(Runner3Name))
{
MessageBox.Show("The Runner 3 Name cannot be empty ", "Invalid Runner Name",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (!double.TryParse(Runner1TimetextBox.Text, out Runner1Time))
{
MessageBox.Show("Please Input a Positive number for Runner 1", "Invalid Input",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (!double.TryParse(Runner2TimetextBox.Text, out Runner2Time))
{
MessageBox.Show("Please Input a Positive number for Runner 2", "Invalid Input",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (!double.TryParse(Runner3TimetextBox.Text, out Runner3Time))
{
MessageBox.Show("Please Input a Positive number for Runner 3", "Invalid Input",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//else if (Runner1Time == Runner2Time & Runner1Time == Runner3Time)
//{
// FirstPlacetextBox.Text = Runner1Name.ToString();
// FirstPlacetextBox.Text = Runner2Name.ToString();
// FirstPlacetextBox.Text = Runner3Name.ToString();
//}
else if (Runner1Time >= Runner2Time & Runner1Time >= Runner3Time)
{
FirstPlacetextBox.Text = Runner1Name.ToString();
}
else if (Runner2Time >= Runner1Time & Runner2Time >= Runner3Time)
{
FirstPlacetextBox.Text = Runner2Name.ToString();
}
else if (Runner3Time >= Runner2Time & Runner3Time >= Runner1Time)
{
FirstPlacetextBox.Text = Runner3Name.ToString();
}
else if (Runner1Time <= Runner2Time & Runner1Time <= Runner3Time)
{
SecondPlacetextBox.Text = Runner1Name.ToString();
}
else if (Runner2Time <= Runner1Time & Runner2Time <= Runner3Time)
{
SecondPlacetextBox.Text = Runner2Name.ToString();
}
else if (Runner3Time <= Runner2Time & Runner3Time <= Runner1Time)
{
SecondPlacetextBox.Text = Runner3Name.ToString();
}
// else if ()
{
}
}
private void Closebutton_Click(object sender, EventArgs e)
{
this.Close();
}
private void Resetbutton_Click(object sender, EventArgs e)
{
//clear runnername textboxes
Runner1NametextBox.Text = string.Empty;
Runner2NametextBox.Text = string.Empty;
Runner3NametextBox.Text = string.Empty;
//clear runnertime
Runner1TimetextBox.Text = "";
Runner2TimetextBox.Text = "";
Runner3TimetextBox.Text = "";
//clears result textbox
FirstPlacetextBox.Text = "";
SecondPlacetextBox.Text = "";
ThirdPlacetextBox.Text = "";
You can do like this
Dictionary<string, double> results = new Dictionary<string, double>();
// Add your runners.
results.Add(Runner1Name, Runner1Time);
results.Add(Runner2Name , Runner2Time);
results.Add(Runner3Name , Runner2Time);
var bestTime = results.Min(item => item.Value);
var worstTime = results.Max(item => item.Value);
foreach (var item in results)
{
if (item.Value == bestTime)
{
Console.WriteLine($"First place {item.Key}");
continue;
}
if (item.Value == worstTime)
{
Console.WriteLine($"Third place {item.Key}");
continue;
}
Console.WriteLine($"Second place {item.Key}");
}
Your function code:
private void Calculatebutton_Click(object sender, EventArgs e)
{
string Runner1Name;
string Runner2Name;
string Runner3Name;
double Runner1Time;
double Runner2Time;
double Runner3Time;
//double FirstPlace;
//double SecondPlace;
//double ThirdPlace;
//get runner names
Runner1Name = Runner1NametextBox.Text;
Runner2Name = Runner2NametextBox.Text;
Runner3Name = Runner3NametextBox.Text;
//check if Runner1Name is empty
if (string.IsNullOrEmpty(Runner1Name))
{
MessageBox.Show("The Runner 1 Name cannot be empty ", "Invalid Runner Name",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//check if Runner1Name is empty
else if (string.IsNullOrEmpty(Runner2Name))
{
MessageBox.Show("The Runner 2 Name cannot be empty ", "Invalid Runner Name",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (string.IsNullOrEmpty(Runner3Name))
{
MessageBox.Show("The Runner 3 Name cannot be empty ", "Invalid Runner Name",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (!double.TryParse(Runner1TimetextBox.Text, out Runner1Time))
{
MessageBox.Show("Please Input a Positive number for Runner 1", "Invalid Input",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (!double.TryParse(Runner2TimetextBox.Text, out Runner2Time))
{
MessageBox.Show("Please Input a Positive number for Runner 2", "Invalid Input",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (!double.TryParse(Runner3TimetextBox.Text, out Runner3Time))
{
MessageBox.Show("Please Input a Positive number for Runner 3", "Invalid Input",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Dictionary<string, double> results = new Dictionary<string, double>();
results.Add(Runner1Name, Runner1Time);
results.Add(Runner2Name , Runner2Time);
results.Add(Runner3Name , Runner2Time);
var bestTime = results.Min(item => item.Value);
var worstTime = results.Max(item => item.Value);
foreach (var item in results)
{
if (item.Value == bestTime)
{
FirstPlacetextBox.Text = item.Key;
continue;
}
if (item.Value == worstTime)
{
ThirdPlacetextBox.Text = item.Key;
continue;
}
SecondPlacetextBox.Text = item.Key;
}
}

Search a record before saving it

I'm developing a simple inventory program that store the hardware devices using C# sql
In my program before I save the record, I want to search for serial number if it exist before I save it or add it in my records to avoid the duplicate, and I receive this exception error:
Syntax error: Missing operand after 'No' operator
Below is my code.
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.Data.SqlServerCe;
namespace DataBaseApplication
{
public partial class Form1 : Form
{
#region Fields
SqlDataAdapter dataAdapter;
DataSet ds;
// DataRowView drView;
CurrencyManager crmng;
SqlConnection con;
ToolTip tootip;
int inc = 0;
#endregion
public Form1()
{
InitializeComponent();
}
#region Connetion to the DataBase and fill the DataSet Table
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'impiDbDataSet1.Impi' table. You can move, or remove it, as needed.
//this.impiTableAdapter1.Fill(this.impiDbDataSet1.Impi);
// TODO: This line of code loads data into the 'impiDbDataSet.Impi' table. You can move, or remove it, as needed.
//this.impiTableAdapter.Fill(this.impiDbDataSet.Impi);
try
{
string conStrings = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\ImpiDb.mdf;Integrated Security=True;Connect Timeout=30";
string sql = "Select * from Impi";
con = new SqlConnection(conStrings);
con.Open();
dataAdapter = new SqlDataAdapter(sql, con);
ds = new DataSet();
dataAdapter.Fill(ds, "Impi");
impdg.DataSource = ds.Tables["Impi"].DefaultView;
crmng = (CurrencyManager)impdg.BindingContext[ds.Tables[0]];
tootip = new ToolTip();
con.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
#region Save the Records to the DataBase
private void btnSave_Click(object sender, EventArgs e)
{
try
{
System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(dataAdapter);
// cb.DataAdapter.Update(ds.Tables["Impi"]);
DataRow dr = ds.Tables["Impi"].NewRow();
dr[0] = txtSerial.Text;
if (txtName.Text != "")
{
dr[1] = txtName.Text;
//Busy trying to solve exception errors and saving the record functionality without duplicating primary key
}
if (cbModel.Text == "MK1" || cbModel.Text == "MK2")
{
dr[2] = cbModel.Text;
}
if (cbStatus.Text == "Serviceble" || cbStatus.Text == "Unserviceble")
{
dr[3] = cbStatus.Text;
}
if (cbDeprtmnt.Text == "AIR" || cbDeprtmnt.Text == "LAND" || cbDeprtmnt.Text == "NAVY" || cbDeprtmnt.Text == "SPECIAL FORCE")
{
dr[4] = cbDeprtmnt.Text;
}
// ds.Tables["Impi"].Rows.Add(dr);
//This is where i stopped trying to figure out how to save my records properly
if (txtSerial.Text.Length!=0)
{
bool search = SearchSerialNumberBeforeSave(txtSerial.Text);
if (search == false)
{
DialogResult dr2 = MessageBox.Show("Are you sure you want to save this serial number", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr2 == DialogResult.Yes)
{
ds.Tables["Impi"].Rows.Add(dr);
dataAdapter.Update(ds, "Impi");
MessageBox.Show("Serial Number Added Successful");
}
// System.Data.SqlClient.SqlCommandBuilder cb;
//cb = new System.Data.SqlClient.SqlCommandBuilder(dataAdapter);
} //cb.DataAdapter.Update(ds.Tables["Impi"]);
else
{
MessageBox.Show("This Serial Number Exist and will create the duplicate.\nSerial Number not Saved");
MessageBox.Show("Data Entry was not saved", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Please Enter a Impi Serial Number","Data Entry");
txtSerial.Text = "Please Enter Impi Serial Number";
txtSerial.ForeColor = Color.Red;
tootip.SetToolTip(txtSerial, txtSerial.Text);
}
// crmng.Position += 1;
// inc = crmng.Position - 1;
// btnAdd.Enabled = true;
// btnSave.Enabled = false;
if (txtName.Text.Length==0)
{
txtName.Text = "Please Enter the Track Number";
txtName.ForeColor = Color.Red;
tootip.SetToolTip(txtName, txtName.Text);
}
if (cbModel.Text.Length == 0)
{
cbModel.Text = "Please Select the Model Of the device";
cbModel.ForeColor = Color.Red;
tootip.SetToolTip(cbModel, cbModel.Text);
}
if (cbStatus.Text.Length == 0)
{
cbStatus.Text = "Please Select the status of the device";
cbStatus.ForeColor = Color.Red;
tootip.SetToolTip(cbStatus, cbStatus.Text);
}
if (cbDeprtmnt.Text.Length == 0)
{
cbDeprtmnt.Text = "Please Select the assigned department";
cbDeprtmnt.ForeColor = Color.Red;
}
else
{
MessageBox.Show("Data Entry was not Saved", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
}
#endregion
#region Search Method
public bool SearchSerialNumberBeforeSave(String name)
{
int result = 0;
DataRow[] retRows;
bool val;
//This line of code give this exception error Syntax error: Missing operand after 'No' operator.
retRows = ds.Tables["Impi"].Select("Serial No='" + name + "'");
result = retRows.Length;
if (result > 0)
{
val = true;
}
else
{
val = false;
}
return val;
}
#endregion
}
}
The space in Serial Nois causing this issue.
In order to solve it replace Serial No with [Serial No]
retRows = ds.Tables["Impi"].Select("[Serial No]='" + name + "'");
Take a look at this thread, It asks about the same issue.

Performing multiple validations on one field C#

I have to validate the textboxes to check if they are a number and if they are in the database. Only problem is I can only seem to get it to check for validity or if they are numeric. How can change this to get both validations?
it validates to make sure there is something in the textboxes:
if (string.IsNullOrEmpty(employeeIDTextBox.Text) && (string.IsNullOrEmpty(JobIDTextBox.Text)))
Then it looks to see if the value is numeric, then if it does it checks to see if the person exists, then sets the values
else if (string.IsNullOrEmpty(JobIDTextBox.Text))
{
if (!Int32.TryParse(JobIDTextBox.Text, out number1))
{
using (dbConn)
{
ReportGrid newGrid = new ReportGrid();
if (newGrid.isValidEmp(Int32TryParseSafe(employeeIDTextBox.Text)))
{
newGrid.startDate = startingdateTimePicker.Value;
newGrid.endDate = endingdateTimePicker.Value;
newGrid.EmployeeID = Int32TryParseSafe(employeeIDTextBox.Text);
newGrid.JobID = Int32TryParseSafe(JobIDTextBox.Text);
newGrid.ShowDialog();
}
else
{
MessageBox.Show("No ID found for the employee.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
Then it does the same for the other textbox
else if (string.IsNullOrEmpty(employeeIDTextBox.Text))
{
if (!Int32.TryParse(emplyeeIDLabel.Text, out number2))
{
using (dbConn)
{
ReportGrid newGrid = new ReportGrid();
if (newGrid.isValidJob(Int32TryParseSafe(JobIDTextBox.Text)))
{
newGrid.startDate = startingdateTimePicker.Value;
newGrid.endDate = endingdateTimePicker.Value;
newGrid.EmployeeID = Int32TryParseSafe(employeeIDTextBox.Text);
newGrid.JobID = Int32TryParseSafe(JobIDTextBox.Text);
newGrid.ShowDialog();
}
else
{
MessageBox.Show("No ID found for that job.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
else
MessageBox.Show("Must be a number.");
}
Here is the whole code
try
{
if (string.IsNullOrEmpty(employeeIDTextBox.Text) && (string.IsNullOrEmpty(JobIDTextBox.Text)))
{
MessageBox.Show("Please enter a EmployeeID or JobID.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (string.IsNullOrEmpty(JobIDTextBox.Text))
{
if (!Int32.TryParse(JobIDTextBox.Text, out number1))
{
using (dbConn)
{
ReportGrid newGrid = new ReportGrid();
if (newGrid.isValidEmp(Int32TryParseSafe(employeeIDTextBox.Text)))
{
newGrid.startDate = startingdateTimePicker.Value;
newGrid.endDate = endingdateTimePicker.Value;
newGrid.EmployeeID = Int32TryParseSafe(employeeIDTextBox.Text);
newGrid.JobID = Int32TryParseSafe(JobIDTextBox.Text);
newGrid.ShowDialog();
}
else
{
MessageBox.Show("No ID found for the employee.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
else
MessageBox.Show("Must be a number.");
if (startingdateTimePicker.Value > endingdateTimePicker.Value)
{
MessageBox.Show("Starting data can not be after than ending date.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else if (string.IsNullOrEmpty(employeeIDTextBox.Text))
{
if (!Int32.TryParse(emplyeeIDLabel.Text, out number2))
{
using (dbConn)
{
ReportGrid newGrid = new ReportGrid();
if (newGrid.isValidJob(Int32TryParseSafe(JobIDTextBox.Text)))
{
newGrid.startDate = startingdateTimePicker.Value;
newGrid.endDate = endingdateTimePicker.Value;
newGrid.EmployeeID = Int32TryParseSafe(employeeIDTextBox.Text);
newGrid.JobID = Int32TryParseSafe(JobIDTextBox.Text);
newGrid.ShowDialog();
}
else
{
MessageBox.Show("No ID found for that job.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
else
MessageBox.Show("Must be a number.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
I could be mistaken but is this line possibly the problem?
if (!Int32.TryParse(emplyeeIDLabel.Text, out number2))
The exclamation point reverses the bool so if the text successfully parses as a number the TryParse function returns true but by using the exclamation the if statement resolves to false. Therefore you are sending the code to else statement which states that it is not a number.
Also, try using "Return" to avoid nested ifs.
if (string.IsNullOrEmpty(employeeIDTextBox.Text) && (string.IsNullOrEmpty(JobIDTextBox.Text)))
{
MessageBox.Show("Please enter a EmployeeID or JobID.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Return;
}
There's no need for an else at this point because the if the if statement resolves to true you will return from the method.
Nested if statements are frequently necessary but they should be avoided when they can to make code clearer to read for maintenance.

Categories

Resources