Can someone help me... I am new to vb.net with sql connection and I can't fix this error : variable name '@date' has already been declared. Variable names must be unique--

I need this to be fixed "ASAP" Im running out of time here because of the error

here is my code

thank you in advance for the reply

Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        accdate = dtpdate.Value 'trial for the variable name '@date' error

        Call conecDB()
        Call disControl()
            If invalidSaveEntry() = True Then
                Call enaControl() 'enable text field
                Exit Sub
            End If
            'Start Save

            SQL = "Insert into tblstud_accdata(accdate,lastname,firstname,middlename,age) values(@date,@lname,@fname,@mname,@age)"
            ' Add Parameters to Command Parameters collection
            comDB.Parameters.Add("@date", SqlDbType.Date).Value = accdate
            comDB.Parameters.Add("@lname", SqlDbType.VarChar, 50).Value = txtLname.Text
            comDB.Parameters.Add("@fname", SqlDbType.VarChar, 50).Value = txtFname.Text
            comDB.Parameters.Add("@mname", SqlDbType.VarChar, 50).Value = txtMname.Text
            comDB.Parameters.Add("@age", SqlDbType.Int).Value = txtAge.Text()
            Call execComDB(SQL)    

            MsgBox("Record(s) saved...", MsgBoxStyle.Information, "Record(s) saved...")
            If MsgBox("Do you want to add new record(s) ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirmation...") = MsgBoxResult.Yes Then
                Call cleartxt()
                Call enaControl()

                Me.Close()    'Close the form
                ' Display new record
                SQL = "Select * from tblstud_accdata " & "order by accno desc"
                Call dispRec(SQL)
                Call frmSearch.dispRecCount() 'Display record count
                '--- End of displaying new record

            End If

        Catch ex As Exception
            Call closeDB()

        End Try
    End Sub

Edited by reimar23: add details

4 Years
Discussion Span
Last Post by reimar23

He's right, in naming you database fields try to include tablename_[fieldname]. I encountered that issue before and that was the word PASSWORD, I did'nt know it is a reserved word.


Hi there! :) thanks for the reply

I try to change the param from '@date' to '@dtacc' but same error occurs...

Maybe Im missing something in my code but my program add the first record I input then once I tried to enter another the variable name error come out..

Your reply is really appreciated

thnak you and God Bless :)

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.