D
Daniel
Hi Group,
Why does the below code not generate an error? I have a table with x
number of records. Each record is read from the DB into a hashtable.
Then I add to the hashtable additional keys. From here, i run through
each key in the hashtable and change the associated value. Now, when I
update the DB with the keys and values from the hashtable, all works
well. However, I also added to the hashtable extra items. So, as far
as I am concerned, when the code tries to do an update for a record that
does not exist in the table it should generate an error because it could
not find it. However, it just ignores it and continues as if everything
is great. I have not added any error handling to the code so in theory
it should complain.
Here is the code.
Dim FileTable as new HashTable
ScanDA = New SqlDataAdapter
ScanConStr = "server=localhost;uid=SA;password=123;database=myDB"
ScanConn = New SqlConnection(ScanConStr)
ScanQuery = "SELECT FilePath,Comment FROM myTable"
ScanCMD = New SqlCommand(ScanQuery, ScanConn)
ScanDA.SelectCommand = ScanCMD
ScanConn.Open()
For Each HashLine As DictionaryEntry In FileTable
UpdateMD5Cmd = "UPDATE myTable SET " & Chr(34) & "newMD5" & Chr(34) &
"='updated' WHERE " & Chr(34) & "FilePath" & Chr(34) & "='" &
HashLine.Key & "'"
ScanCMD.CommandText = UpdateMD5Cmd
ScanCMD.ExecuteNonQuery()
Next
ScanConn.Close()
So, it loads all the file names and comments into the hashtable
(filename is the key and the comment is the value). Then it processes
the comments. After that, it uploads the keys back into the FilePath
column and the values back into the comments column.
So, it should throw an error because it cannot find the new files i
added to the hashtable.
I hope this is clear! Thanks.
Why does the below code not generate an error? I have a table with x
number of records. Each record is read from the DB into a hashtable.
Then I add to the hashtable additional keys. From here, i run through
each key in the hashtable and change the associated value. Now, when I
update the DB with the keys and values from the hashtable, all works
well. However, I also added to the hashtable extra items. So, as far
as I am concerned, when the code tries to do an update for a record that
does not exist in the table it should generate an error because it could
not find it. However, it just ignores it and continues as if everything
is great. I have not added any error handling to the code so in theory
it should complain.
Here is the code.
Dim FileTable as new HashTable
ScanDA = New SqlDataAdapter
ScanConStr = "server=localhost;uid=SA;password=123;database=myDB"
ScanConn = New SqlConnection(ScanConStr)
ScanQuery = "SELECT FilePath,Comment FROM myTable"
ScanCMD = New SqlCommand(ScanQuery, ScanConn)
ScanDA.SelectCommand = ScanCMD
ScanConn.Open()
For Each HashLine As DictionaryEntry In FileTable
UpdateMD5Cmd = "UPDATE myTable SET " & Chr(34) & "newMD5" & Chr(34) &
"='updated' WHERE " & Chr(34) & "FilePath" & Chr(34) & "='" &
HashLine.Key & "'"
ScanCMD.CommandText = UpdateMD5Cmd
ScanCMD.ExecuteNonQuery()
Next
ScanConn.Close()
So, it loads all the file names and comments into the hashtable
(filename is the key and the comment is the value). Then it processes
the comments. After that, it uploads the keys back into the FilePath
column and the values back into the comments column.
So, it should throw an error because it cannot find the new files i
added to the hashtable.
I hope this is clear! Thanks.