c#


C # fill datatable using loops - how?


First of all, I'm just a beginner in C#, so.....don't laugh :-)
OK, I have DataTable named "Changeable" with Columns (Id, A, B, C, D, Fdiv).
The values of A, B, C, D are integers (numbers), Fdiv is decimal number with 13 decimal places and Id is AutoNumber.
I have four(4) counters( loops) like code below, with all possible No. of combination is 21^4
for ( int A = 10; A <= 31; A++)
{
for ( int B = 10; B <= 31; B++)
{
for ( int C = 10; C <= 31; C++)
{
for ( int D = 10; D <= 31; D++)
{
while (A == 31)
{
Fdiv = A/B * C/D
//Code to fill all 5 values in
// DataTable "Changeable", automatic
}
}
}
}
}
How to do this?
Filling a data table with a loop.
private void AddDataToDGV()
{
DataTable dt = new DataTable();
//create some columns for the datatable
DataColumn dc = new DataColumn("ItemName");
DataColumn dc2 = new DataColumn("ItemValue");
DataColumn dc3 = new DataColumn("Blah");
DataColumn dc4 = new DataColumn("Bleh");
//add the columns to the datatable
dt.Columns.Add(dc);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
//create 5 rows of irrelevant information
//this is the actual answer to your question
for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();//create a new row based on the existing "row model"
dr["ItemName"] = "Item" + i + "Name";
dr["ItemValue"] = "Item" + i + "Value";
dr["Blah"] = "Item" + i + "Blah";
dr["Bleh"] = "Item" + i + "Bleh";
dt.Rows.Add(dr);//add the row to the DataTable
}
}

Related Links

dragablz TabablzControl wpf disable tab switch and Drag
Make rest of the characters of text display, instead of getting repeat?
WPF | Attach a frame to more page
Entity Framework 6 Code First Table Per Type (TBT) With Abstract Generic Base Class - Invalid Column Errors
Handle Mouse Hover on Titlebar of Form - Show Title of a Minimized MDI Child in ToolTip
Why is it a good practise to create a new instance of Stream per each I/O operation? (C#)
Remote launch and shutdown of Azure server within .Net/C#
Number looping get row number(01,02,03)
How can I change the JSON date serialization format for as single service in ServiceStack 3?
Binary Formatter - Type UserControl is not marked as serializable
compile schemas with included xsd files
How to rename a property in Xamarin Binding Library
Format tab in RichTextBox
Opening an Excel file in C# using Process.Start
How to check if string not equals a Boolean
Saving image from inkCanvas as png or jpeg file

Categories

HOME
asterisk
autohotkey
internet-explorer
indexing
service
microcontroller
latex
salesforce-lightning
opengl-es
token
angularjs-ng-repeat
ethereum
hql
luis
project-structure
google-drive-android-api
aspxgridview
android-wear-2.0
expressionengine
drombler-fx
meteor-accounts
pypy
xlib
opencsv
choco
node-soap
motherboard
redhat-brms
angular-fullstack
rivets.js
dna-sequence
activesupport
selection-sort
opticalflow
nls
qt3d
firebase-job-dispatcher
optional-parameters
glade
jira-agile
nsoperationqueue
std
google-app-engine-php
web-performance
imageicon
gulp-cdnizer
gitk
serial-communication
tess4j
stereotype
vspackage
page-refresh
gcc-warning
valdr-bean-validation
crystal-reports-7
fxmlloader
clearcanvas
xmlserializer
cs193p
opencobol
farpoint-spread
image-preloader
iwork
internet-radio
kernel-density
mdp
node-amqp
mahara
facebook-likebox
svg-android
azure-pack
qgraphicsscene
mandelbrot
friendly-url
configurationsection
linear-interpolation
states
github-archive
erlide
nserror
socketasynceventargs
apache-commons-email
capitalization
zend-validate
gmagick
noise-reduction
llblgen
nscharacterset
activescaffold
pitch-shifting
konsole
cstring
cons
scalable

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile