How would you insert records into a SQL Server table via a loop using C# when comparing a field to an incremented variable?

zimmer9
zimmer9 used Ask the Experts™
on
I am developing a C# Windows platform application using VS2005.
I am also using SQL Server 2005 tables as the back end database.

How would you code a loop so that the int variable intBranch, is incremented by 1 starting with the initial value of 001 through 999 and for each value, intBranch
is compared to the value of field Left([CPS Account Number],3) of table tblFlLNExp.

If Left([CPS Account Number],3) of table tblFlLNExp = intBranch
then

INSERT INTO tblFlLNMod SELECT tblFlLNExp.*   FROM
tblFlLNExp WHERE LEFT([CPS Account Number],3 = intBranch
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Security Specialist
Commented:
if tblFlLNExp is a table in the database then you have to make sql statement to retrive its data
and store it in a data table

example

dim dt as new datatable
dt=get the data from database()
then you have to loop through your datatable and compare it with your value

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial