Solved

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
2
313 Views
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
then

INSERT INTO tblFlLNMod SELECT tblFlLNExp.*   FROM
tblFlLNExp WHERE LEFT([CPS Account Number],3 = intBranch
0
Comment
Question by:zimmer9
2 Comments
 
LVL 17

Expert Comment

by:Dushan911
ID: 38717711
0
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 500 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

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
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now