Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I make a function to save datagridview to Database (Report)

VB
Public Function SaveD()
    Dim I As Integer

    For I = 0 To PDG.Rows.Count - 1
        BuyBillTableAdapter1.Insert(PDG.Item(0, I).Value, PDG.Item(1, I).Value, PDG.Item(2, I).Value, PDG.Item(3, I).Value, PDG.Item(4, I).Value, Label13.Text)
    Next
End Function


but there is error
"Specified cast is not valid."

How I can correct it ?
Posted

1 solution

"Specified cast is not valid."
Based on the error, it is pretty clear that there is a data-type mismatch somewhere. If the error comes from above code lines, since you have not explicitly tried to cast any value, my guess would be that one of the values you try to insert is not expected to be of type string. Above insert parameters have all the string datatype. Is that really expected? Check if there is a mismatch in what is passed and what is expected.
 
Share this answer
 
Comments
fjdiewornncalwe 10-Jan-13 9:16am    
+5. Excellent Advice.
Sandeep Mewara 10-Jan-13 9:18am    
Thanks Marcus. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900