I'm looping through an array to check whether or not data in the array already exists in my database. The problem is, after the loop returns true, it returns false no matter what.
Ex: Companys Table contains '123', Operations Table contains '321'. array = {'123', '321'}. In this case my return will be array[0] exists in CompanyName, array[1] does not exist in Operations (even though it does.)
Ex: array = {"", "321"}. Nothing happens for array[0] because == "". Returns array[1] exists in Operations.
I'm not sure what I am missing, perhaps I misunderstand how an if else statement works in a for loop.
for (int j = 0; j < user_inputs.Length; j++)
{
MessageBox.Show("Working on " + user_inputs[j] + "\n j: " + j);
if (j == 0)
{
if (company_value != "")
{
//Getting user input and set to items
string[] items = { company_value };
//Check that data is not already in DB
Class_DB checkExist = new Class_DB();
Boolean dataExist = false;
dataExist = checkExist.CheckData_Company(items, conn);
if (dataExist == true)
{
MessageBox.Show("Company ALREADY Exist in DB: " + dataExist + " " + items[0]);
}
else
{
MessageBox.Show("Company does not Exist: " + items[0]);
}
}
continue;
}
else if (j == 1)
{
if (operation_value != "")
{
//Getting user input and set to items
string[] items = { operation_value };
//Check that data is not already in DB
Class_DB checkExist = new Class_DB();
Boolean dataExist = false;
dataExist = checkExist.CheckData_Operation(items, conn);
if (dataExist == true)
{
MessageBox.Show("Operation ALREADY Exists in DB: " + dataExist + " " + items[0]);
}
else
{
MessageBox.Show("Operation does not Exist: " + items[0]);
}
}
continue;
}
}
/* This goes on for 6 separate if([value] != "") statements */
Aucun commentaire:
Enregistrer un commentaire