C
Co
Hi All,
I have following code to duplicate records in a database table:
When I duplicate one record everything works but when I try to add
more records I get this error:
"Conversion from type dbnull to type string is not valid."
The code stops at the lien saying:
dr = ds.Tables(0).Rows(j)
Sub FileDuplicator(ByVal oldNode As Integer, ByVal newNode As Integer,
ByVal fileID() As String)
Dim sql As String = "SELECT * FROM Bestanden WHERE Lokatie=" &
oldNode
Dim strTable As String = "Bestanden"
Dim da As New OleDb.OleDbDataAdapter(sql, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim ds As New DataSet
Dim i As Integer
Dim newRow As DataRow
Try
da.SelectCommand = New OleDb.OleDbCommand(sql, conn)
da.Fill(ds, strTable)
Dim dr As DataRow
For i = 0 To fileID.Length - 1
For j As Integer = ds.Tables(0).Rows.Count - 1 To 0
Step -1
dr = ds.Tables(0).Rows(j)
'For Each dr In ds.Tables(0).Rows
If CStr(dr.Item("Id")) = fileID(i) Then
'create this file in the folder
newRow = ds.Tables(strTable).NewRow()
newRow("filenaam") = dr.Item("filenaam")
newRow("status") = FixNull(dr.Item("status"))
newRow("lokatie") = newNode
newRow("extensie") = dr.Item("extensie")
newRow("grootte") = FixNull(dr.Item
("grootte"))
newRow("datum_gemaakt") = FixNull(dr.Item
("datum_gemaakt"))
newRow("datum_gewijzigd") = FixNull(dr.Item
("datum_gewijzigd"))
newRow("expires") = FixNull(dr.Item
("expires"))
newRow("hddlokatie") = FixNull(dr.Item
("hddlokatie"))
newRow("samenvatting") = dr.Item
("samenvatting")
newRow("kenmerk") = FixNull(dr.Item
("kenmerk"))
newRow("auteur") = FixNull(dr.Item("auteur"))
newRow("soort") = FixNull(dr.Item("soort"))
newRow("inuit") = FixNull(dr.Item("inuit"))
ds.Tables(strTable).Rows.Add(newRow)
End If
Next
Next
'sent the updated dataSet to the database
da.Update(ds, strTable)
Catch oException As OleDbException
MessageBox.Show(oException.Message)
Catch oException As Exception
MessageBox.Show(oException.Message)
End Try
conn.Close()
End Sub
Any thoughts?
Regards
Marco
I have following code to duplicate records in a database table:
When I duplicate one record everything works but when I try to add
more records I get this error:
"Conversion from type dbnull to type string is not valid."
The code stops at the lien saying:
dr = ds.Tables(0).Rows(j)
Sub FileDuplicator(ByVal oldNode As Integer, ByVal newNode As Integer,
ByVal fileID() As String)
Dim sql As String = "SELECT * FROM Bestanden WHERE Lokatie=" &
oldNode
Dim strTable As String = "Bestanden"
Dim da As New OleDb.OleDbDataAdapter(sql, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim ds As New DataSet
Dim i As Integer
Dim newRow As DataRow
Try
da.SelectCommand = New OleDb.OleDbCommand(sql, conn)
da.Fill(ds, strTable)
Dim dr As DataRow
For i = 0 To fileID.Length - 1
For j As Integer = ds.Tables(0).Rows.Count - 1 To 0
Step -1
dr = ds.Tables(0).Rows(j)
'For Each dr In ds.Tables(0).Rows
If CStr(dr.Item("Id")) = fileID(i) Then
'create this file in the folder
newRow = ds.Tables(strTable).NewRow()
newRow("filenaam") = dr.Item("filenaam")
newRow("status") = FixNull(dr.Item("status"))
newRow("lokatie") = newNode
newRow("extensie") = dr.Item("extensie")
newRow("grootte") = FixNull(dr.Item
("grootte"))
newRow("datum_gemaakt") = FixNull(dr.Item
("datum_gemaakt"))
newRow("datum_gewijzigd") = FixNull(dr.Item
("datum_gewijzigd"))
newRow("expires") = FixNull(dr.Item
("expires"))
newRow("hddlokatie") = FixNull(dr.Item
("hddlokatie"))
newRow("samenvatting") = dr.Item
("samenvatting")
newRow("kenmerk") = FixNull(dr.Item
("kenmerk"))
newRow("auteur") = FixNull(dr.Item("auteur"))
newRow("soort") = FixNull(dr.Item("soort"))
newRow("inuit") = FixNull(dr.Item("inuit"))
ds.Tables(strTable).Rows.Add(newRow)
End If
Next
Next
'sent the updated dataSet to the database
da.Update(ds, strTable)
Catch oException As OleDbException
MessageBox.Show(oException.Message)
Catch oException As Exception
MessageBox.Show(oException.Message)
End Try
conn.Close()
End Sub
Any thoughts?
Regards
Marco