Please support our C# advertiser: Programming Forums
Views: 1217 | Replies: 4
![]() |
•
•
Join Date: Apr 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Dear All,
I have a value, strObjectAPIID, and I am comparing it to a dataset value in a loop. What i want is, if the value is equal, do not do anything, but if it is not equal, write it to the table.
However, i have to check the value with the whole dataset, for example i have the following:-
strObjectAPIID = abc123
and the values in the dataset are aaa123, aab123, abc123.
So the first value is not equal, however the third value is equal, so I am not supposed to write it in the table.
So basically, what I want to do is, if strObjectAPIID is not existing in the whole dataset, then commit to table.
At the moment my current code is like this:-
for (int j = 0; j < dsExisitingCodes.Tables[0].Rows.Count; j++)
{
rowCounter = dsExisitingCodes.Tables[0].Rows.Count;
strTableAPIID = (dsExisitingCodes.Tables[0].Rows[j][0].ToString());
if ( strObjectAPIID == strTableAPIID)
{
bFound = true;
break;
}
}
And what happens is that if the value is not equal, then I am loosing it. How can i arrange it to commit to the database?
I have a value, strObjectAPIID, and I am comparing it to a dataset value in a loop. What i want is, if the value is equal, do not do anything, but if it is not equal, write it to the table.
However, i have to check the value with the whole dataset, for example i have the following:-
strObjectAPIID = abc123
and the values in the dataset are aaa123, aab123, abc123.
So the first value is not equal, however the third value is equal, so I am not supposed to write it in the table.
So basically, what I want to do is, if strObjectAPIID is not existing in the whole dataset, then commit to table.
At the moment my current code is like this:-
for (int j = 0; j < dsExisitingCodes.Tables[0].Rows.Count; j++)
{
rowCounter = dsExisitingCodes.Tables[0].Rows.Count;
strTableAPIID = (dsExisitingCodes.Tables[0].Rows[j][0].ToString());
if ( strObjectAPIID == strTableAPIID)
{
bFound = true;
break;
}
}
And what happens is that if the value is not equal, then I am loosing it. How can i arrange it to commit to the database?
•
•
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,166
Reputation:
Rep Power: 7
Solved Threads: 59
Have you initialised bFound to False anywhere ?
•
•
Join Date: Jul 2005
Location: Dallas, TX
Posts: 482
Reputation:
Rep Power: 4
Solved Threads: 19
try this:
bFound = false;
rowCounter = dsExisitingCodes.Tables[0].Rows.Count;
for (int j = 0; j < dsExisitingCodes.Tables[0].Rows.Count && !bFound; j++){
strTableAPIID = dsExisitingCodes.Tables[0].Rows[j][0].ToString();
bFound = (strObjectAPIID==strTableAPIID);
} Hi,
The previous post is pretty much optimized and must have solved your problem but if you have many entires on your DB you might want to use an SQL query like (Select * from <tablename> where <fieldname> = '<idyousearchfor>') and then just check for wether the number of rows returned is greater then 0.
Loren Soth
The previous post is pretty much optimized and must have solved your problem but if you have many entires on your DB you might want to use an SQL query like (Select * from <tablename> where <fieldname> = '<idyousearchfor>') and then just check for wether the number of rows returned is greater then 0.
Loren Soth
Crimson K. Software _________________________________________________________________ Crimson K. Blog
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode