New to databases and am can read vb.net or c# code. I want to match filenames in a folder to a master list of those filenames with their descriptions and create a subset to display in a datagridview control. "Filename" is a primary key in both tables:
Table "MasterList" <-- 50,000 records
Filename
Title
Table "FoundFiles" <-- 2,000 records
Filename
After weeks of reading, I came up with the following and both SQL queries "seem" to give the same result. Am I doing it correctly and is one query "better" than another? I am also confused about the order of the tables in the query. Which is "left" and which is "right" and if I have them correct in the "JOIN"
Dim con As New SqlCeConnection("Data Source=|DataDirectory|\data.sdf")
Dim daMasterList As SqlCeDataAdapter
Dim daSubset As SqlCeDataAdapter
Dim ds As DataSet
Sub table_load(database As String)
ds = New DataSet
daMasterList = New SqlCeDataAdapter(("SELECT * FROM MasterList"), con)
daMasterList.Fill(ds, "MasterList")
daSubset = New SqlCeDataAdapter(("SELECT FoundFiles.Filename, MasterList.Title" & _" FROM FoundFiles" & _
" INNER JOIN MasterList" & _
" ON FoundFiles.Filename = Masterlist.Filename"), con)
daSubset.Fill(ds, "FoundFiles")
' load the table into a DataGridView control
dgvFileList.DataSource = ds.Tables("FoundFiles") 'existing files with titles from the master list
End Sub
This also gives me what I am looking for:
daSubset = New SqlCeDataAdapter(("SELECT * FROM MasterList" & _
" INNER JOIN FoundFiles"
" ON MasterList.Filename = FoundFiles.Filename"), con)
wanted result:
FoundFiles MasterList reduced master or new table
filename1.zip filename1.zip, accounting filename1.zip, accounting
filename2.zip --> filename2.zip, birth certs --> filename2.zip, birth certs
filename5.zip filename3.zip, spreadsheets filename5.zip, websites
filename8.zip filename4.zip, real estate filename8.zip, archived
.... filename5.zip, websites
filename6.zip, games
filename7.zip, presentations
filename8.zip, archived