Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
How can I add arraylist items in Datatable?
Mani Kandan
Sep 14 2016 12:25 PM
228
Reply
Hello Everyone,
How can I add arraylist items in Datatable? I can create a program but, it occured errors.
Kindly answer me with your explanation.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Data;
using
System.Web;
using
System.Collections;
namespace
ConsoleApplication14
{
class
Program
{
static
void
Main(
string
[] args)
{
DataTable table1 =
new
DataTable();
table1.Columns.Add(
"M1"
);
table1.Columns.Add(
"M2"
);
table1.Columns.Add(
"M3"
);
DataRow row1 = table1.NewRow();
row1[
"M1"
] =
"100"
;
row1[
"M2"
] =
"120"
;
row1[
"M3"
] =
"322"
;
table1.Rows.Add(row1);
DataRow row2 = table1.NewRow();
row2[
"M1"
] =
"200"
;
row2[
"M2"
] =
"350"
;
row2[
"M3"
] =
"542"
;
table1.Rows.Add(row2);
DataRow row3 = table1.NewRow();
row3[
"M1"
] =
"300"
;
row3[
"M2"
] =
"120"
;
row3[
"M3"
] =
"544"
;
table1.Rows.Add(row3);
table1.Columns.Add(
"ID"
,
typeof
(
int
));
table1.Columns.Add(
"Name_student"
,
typeof
(String));
DataView view =
new
System.Data.DataView(table1);
DataTable selected =
new
DataTable();
selected = view.ToTable(
true
,
"ID"
,
"Name_student"
,
"M1"
,
"M2"
,
"M3"
);
string
Name_student =
string
.Empty;
int
i = 0;
ArrayList arrlist =
new
ArrayList();
arrlist.Add(
"Mohammad"
);
arrlist.Add(
"Ali"
);
arrlist.Add(
"Fahe"
);
foreach
(DataRow item
in
table1.Rows)
{
foreach
(DataRow row
in
selected.Rows)
{
row[
"Name_student"
] = arrlist[i];
i = i + 1;
for
(
int
j = 0; j <= 3; j++)
{
row[
"ID"
] = j;
}
}
}
var objselelcted = selected;
}
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
How to check if an MS Word is closed in C#
create a List of list