Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I am trying to add numerical value through parameter in access table, I receive aforesaid message. what will be the solution, I have tried as follows:

What I have tried:

Sub DataTrans()
Dbconnection.Open()

MasterReader = MasterCmd.ExecuteReader()

Try

While MasterReader.Read()

IntArr(0) = (MasterReader("Sap_No"))
IntArr(1) = (MasterReader("DesigIndex"))
IntArr(2) = (MasterReader("CurrYear"))

StrArr(0) = (MasterReader("CPF_No".ToString))
StrArr(1) = (MasterReader("Name".ToString))
StrArr(2) = (MasterReader("Designation".ToString))


LvMasterCmd.CommandText = "INSERT INTO LeaveMaster (CPF_No, Name, Designation, MNT, YR, LeaveStatus,CurrYear,Sap_No,DesigIndex)" &
"VALUES (@CPF_No, @Name, @Designation, @MNT, @YR, @LeaveStatus, CurrYear, @Sap_No, @DesigIndex) ; "


Try

LvMasterCmd.Parameters.AddWithValue("@Sap_No", IntArr(0))
LvMasterCmd.Parameters.AddWithValue("@DesigIndex", IntArr(1))
LvMasterCmd.Parameters.AddWithValue("@CurrYear", IntArr(2))

LvMasterCmd.Parameters.AddWithValue("@CPF_No", StrArr(0).ToString)
LvMasterCmd.Parameters.AddWithValue("@Name", StrArr(1).ToString)
LvMasterCmd.Parameters.AddWithValue("@Designation", StrArr(2).ToString)

LvMasterCmd.Parameters.AddWithValue("@MNT", CmbMonth.Text)
LvMasterCmd.Parameters.AddWithValue("@YR", CmbYear.Text)
LvMasterCmd.Parameters.AddWithValue("@LeaveStatus", "N")


LvMasterCmd.ExecuteNonQuery()
LvMasterCmd.Parameters.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End While

Catch ex As Exception
MessageBox.Show(ex.Message)

End Try

Dbconnection.Close()
End Sub
Posted
Updated 15-Jul-18 20:24pm
Comments
Jochen Arndt 16-Jul-18 9:27am    
It might be sourced by the missing '@' in front of CurrYear in he VALUES list of your SQL statement.

1 solution

We can't help: this is going to be largely down to your data, and the design of your database, and we have no access to either.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the line
LvMasterCmd.Parameters.AddWithValue("@Sap_No", IntArr(0))
Then run your code through the debugger. When it hits, use the debugger to look at exactly what you are passing to the DB. Then check the DB table definition and check what datatype that column expects. When it doesn't match, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 

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