• 主页
  • VBS
  • .NET技术
  • VBA
  • VB网络编程
  • VB多媒体
  • VB数据库
  • VB控件
  • VB COM/DCOM
  • VB基础类
  • VB API
JirlangLianHongCh 2014年01月18日
linq 如何left join (帶測試代碼)

linq left join 測試代碼 有數據EXCEL表 謝謝大神幫忙解決下:
2個datatable結果集合併(LEFT JOIN)
excel2003測試表
SUVZHG:
http://pan.baidu.com/s/1i39Nkln
TOPRC:
http://pan.baidu.com/s/1gd417Xp

Function SUVZHG() As DataTable
Dim fileName As String
Dim kk As New OpenFileDialog()
kk.FileName = "SUVZHG"
kk.Filter = "Excle恅璃(*.xls)|*.xls"
If kk.ShowDialog() = DialogResult.OK Then
fileName = kk.FileName
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & fileName & "';Extended Properties=Excel 8.0;"
Dim dr As New DataTable
Dim da As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
Try
da.Fill(dr)
SUVZHG = dr
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End If
End Function
Function TOPRC() As DataTable
Dim fileName As String
Dim kk As New OpenFileDialog()
kk.FileName = "TOPRC"
kk.Filter = "Excle恅璃(*.xls)|*.xls"
If kk.ShowDialog() = DialogResult.OK Then
fileName = kk.FileName
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & fileName & "';Extended Properties=Excel 8.0;"
Dim dr As New DataTable
Dim da As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
Try
da.Fill(dr)
TOPRC = dr
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End If
End Function
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Dim q = From emp In TOPRC() Group Join emc In SUVZHG() On emp("JSX") Equals emc("JSX") Into DataGroup = Group
From row In DataGroup.DefaultIfEmpty()
Select emp, Order = row
DG1.DataSource = q.CopyToDataTable
End Sub
...全文
131 点赞 收藏 4
写回复
4 条回复

还没有回复,快来抢沙发~

发动态
发帖子
VB
创建于2007-09-28

1.1w+

社区成员

11.0w+

社区内容

VB技术相关讨论
社区公告
暂无公告