Hi,
Im having a problem with a program Im trying to write. What i want to do is read a database and where the date is in a specified range add the donation amount. I have 2 types of donations, i want my program to look at which donation type it is and then add it to a total. What im having a problem with is trying to set the data fields = to a string. I may be going about this all wrong, here is exact error i get
An unhandled exception of type System.InvalidCastException occurred in microsoft.visualbasic.dll
Additional information: Cast from type DBNull to type String is not valid
and heres the snipet of code.
myOleDbDataAdapter.Fill(myDataSet, "Donations")
myDataTable = myDataSet.Tables("Donations")
Dim rowDonations As DataRow = myDataTable.NewRow
Resources = rowDonations("Resources Cash/In-Kind")
datemade = rowDonations("Date Donation Made")
donationsamount = rowDonations("Donation Amount")
With myDataSet.Tables
While Not EOF(1)
Input(1, "Resources Cash/In-Kind")
Input(1, "Date Donation Made")
Input(1, "Donation Amount")
If Resources = "Resources In-Kind" Then
donationsinkindtotal = donationsinkindtotal + donationsamount
Else
donationscashtotal = donationscashtotal + donationsamount
End If
End While
End With
The Red line is where the error is given. Ive been playing with it and searching around the web to try and figure this out but im stumped now. Any help would be much appreciated.
Michelle
Im having a problem with a program Im trying to write. What i want to do is read a database and where the date is in a specified range add the donation amount. I have 2 types of donations, i want my program to look at which donation type it is and then add it to a total. What im having a problem with is trying to set the data fields = to a string. I may be going about this all wrong, here is exact error i get
An unhandled exception of type System.InvalidCastException occurred in microsoft.visualbasic.dll
Additional information: Cast from type DBNull to type String is not valid
and heres the snipet of code.
myOleDbDataAdapter.Fill(myDataSet, "Donations")
myDataTable = myDataSet.Tables("Donations")
Dim rowDonations As DataRow = myDataTable.NewRow
Resources = rowDonations("Resources Cash/In-Kind")
datemade = rowDonations("Date Donation Made")
donationsamount = rowDonations("Donation Amount")
With myDataSet.Tables
While Not EOF(1)
Input(1, "Resources Cash/In-Kind")
Input(1, "Date Donation Made")
Input(1, "Donation Amount")
If Resources = "Resources In-Kind" Then
donationsinkindtotal = donationsinkindtotal + donationsamount
Else
donationscashtotal = donationscashtotal + donationsamount
End If
End While
End With
The Red line is where the error is given. Ive been playing with it and searching around the web to try and figure this out but im stumped now. Any help would be much appreciated.
Michelle