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

Posted on 2012-12-23
Medium Priority
Last Modified: 2012-12-27
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

tblFlLNExp WHERE LEFT([CPS Account Number],3 = intBranch
Question by:zimmer9
LVL 17

Expert Comment

by:Dushan De Silva
ID: 38717711
LVL 16

Accepted Solution

Kamal Khaleefa earned 2000 total points
ID: 38717825
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


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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question