TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Karthik K
1k
738
191.7k
datatable loop values into another datatable in c# ?
Apr 4 2019 2:20 AM
Hi,
I want to get the values from datatable through loop and add it to another datatable.
I have a code that adds the current row on every iteration. If anybody knows, Let me know with example Code..
Sample_Code:
string
ChartQry =
"SELECT A.TransDate,concat(DATE_FORMAT(a.transtime,'%h:%00 %p'),'-',DATE_FORMAT(a.transtime,'%h:59 %p')) as Hour,DATE_FORMAT(a.transtime,'%H') as TimeGroup,Date_format(TransTime,'%y-%m-%d %H:00:00') as DateTime, Sum(B.TaxableAmount+B.TaxAmount1+B.TaxAmount2+B.TaxAmount3+B.TaxAmount4+B.TaxAmount5+B.TaxAmount6) As Amount, DATE_FORMAT(a.transtime,'%h:%00 %p') as TM FROM "
+ Branch_AliasName +
".Trans A JOIN "
+ Branch_AliasName +
".TransDetail B on A.Transid=B.Transid Left Join "
+ Branch_AliasName +
".Customers C On a.CustomerNumber=C.CustomerNumber Where (A.BusinessDate Between '"
+ D1 +
"' And '"
+ D2 +
"') And B.ItemStatus<>1 Group by Hour ORDER BY HOUR(a.TransTime);"
;
ReadResult = ObjMainCloud.GetData_DT(ChartQry);
DataTable DtFinaldata =
new
DataTable();
DataRow Dr = DtFinaldata.NewRow();
foreach
(DataRow row
in
ReadResult.Rows)
{
RTimeGroupValue = row[
"TimeGroup"
].ToString();
RAmount = row[
"Amount"
].ToString();
if
(DtFinaldata.Rows.Count > 0)
{
Dr[
"Tm"
] = RTimeGroupValue;
Dr[
"Amount"
] = RAmount;
DtFinaldata.Rows.Add(Dr);
DtFinaldata.AcceptChanges();
}
else
{
DtFinaldata.Columns.Add(
"Tm"
,
typeof
(
string
));
DtFinaldata.Columns.Add(
"Amount"
,
typeof
(
decimal
));
Dr[
"Tm"
] = RTimeGroupValue;
Dr[
"Amount"
] = RAmount;
}
DtFinaldata.Rows.Add(Dr);
DtFinaldata.AcceptChanges();
}
Reply
Answers (
1
)
Please Reslove me from this error {"Cannot find table 0."}
Google login with customized login button