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

I am developing project in Visual Studio-2015 using Access Table in Back end. I have receive aforesaid error while inserting record in table.If I use TWO fields i.e. CurrYear & SAP_No, it works fine but when I try to add THIRD field i.e CPF_No, with parameter it shows Error.

What can I do where field names and field sequences in table are same ?

My Codes are as follows:-

What I have tried:

VB
Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
        '********************************************************************************************

        BtnSave.Enabled = False

        Dbconnection.Close()

        Dbconnection.Open()

        'AddEmpCmd.CommandType = CommandType.Text

        AddEmpCmd.CommandText = "INSERT INTO EMP_MASTER " &
             "(CurrYear, Sap_No, CPF_No) " &
             "VALUES (@CurrYear, @Sap_No, @CPF_No) ; "



        Try
            ' AddEmpCmd.Parameters.AddWithValue("@CurrYear", CmbYear.Text.ToString())
            'AddEmpCmd.Parameters.AddWithValue("@Sap_No", TxtSapID.Text.ToString())
            'AddEmpCmd.Parameters.AddWithValue("@CPF_No", TxtCPFNo.Text.ToString())
            

            AddEmpCmd.ExecuteNonQuery()
            Dbconnection.Close()

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


    End Sub
Posted
Updated 7-Jul-18 5:18am
v2

1 solution

Uncommenting the parameters may help
VB
AddEmpCmd.Parameters.AddWithValue("@CurrYear", CmbYear.Text.ToString())
AddEmpCmd.Parameters.AddWithValue("@Sap_No", TxtSapID.Text.ToString())
AddEmpCmd.Parameters.AddWithValue("@CPF_No", TxtCPFNo.Text.ToString())
 
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