如何匹配两个数据表并获取数据 [英] How to match two datatable and fetch the data

查看:79
本文介绍了如何匹配两个数据表并获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,有人可以建议我。



我正在winforms创建excel报告如果用户选择jan月,这个报告是月份明智的报告

所有日期将在excel即Jan-1-2013,Jan2..Jan31 ..我做了。我创建了一个函数,我在一个DataTable dt1中调用了该函数,填写了那个日期。

接下来在我的数据库中我有tblCalendar表我有两个feild DoEventDate,事件

tblCalendar

DoEventDate活动

1-jan-13 NewYear

14-jan-13 Sankarthi



excel

ExpectedResult

日期活动备注

1jan 2013 Newyear

2Jan







.14 Jan 13 Sankarthi









i fetched(选择DoEventDate,来自tblCalendar的活动)

i保存在datatable dt2 ..

我得到了结果



MYResult

日期活动备注

1jan 2013 Newyear

2Jan Sankaranthi --->这是错误的,应该只在1月14日到来。喜欢上面的预期结果

3





31

Hi guys anyone can suggest me.

I''m creating excel report in winforms this report is month wise report if user select jan month
all date will in the excel i.e Jan-1-2013,Jan2..Jan31.. That i did. I created one function and i called that function in one DataTable dt1 filled that date.
Next in my database i have tblCalendar table there i have two feild DoEventDate, Events
tblCalendar
DoEventDate Events
1-jan-13 NewYear
14-jan-13 Sankarthi

In excel
ExpectedResult
Date Events Remarks
1jan 2013 Newyear
2Jan
3
.
.
.14 Jan 13 Sankarthi
.
.
31

i fetched (select DoEventDate,Events from tblCalendar)
i kept in datatable dt2..
I got result

MYResult
Date Events Remarks
1jan 2013 Newyear
2Jan Sankaranthi---> This is wrong it should come at Jan14 only. like above expectedResult
3
.
.
31

推荐答案

看起来你可以用 LEFT JOIN 来做这个,其中左表有月的所有日期,右表是你的 tblCalendar

请参阅: SQL连接的可视化表示 [ ^ ]
It looks like you could do this with a LEFT JOIN where the left table has all of the dates of the month, and the right table is your tblCalendar.
See: Visual Representation of SQL Joins[^]


这篇关于如何匹配两个数据表并获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆