Hello

How do I rectify this error, please: 'Argument not specified...'?

I have 4 columns in a MS Access database: username, strEmail, hashed, and salted. In my form field (on the Webpage), I have Name (username) and Email (strEmail) which are text fields and correspond to username.Text and strEmail.Text in the attached screenshot.

But how would I correct the "@hashed" and "@salted" errors in the attached screenshot? ArgumentNotSpecified.jpg

Thanks!

Recommended Answers

All 4 Replies

Did you notice that the previous calls you made to .AddWithValue had two parameters? The error states "Argument not specified" so add a value parameter.

Thanks, Reverend Jim, for your reply.

If I do this:

 cmd.Parameters.AddWithValue("@hashed", hashed.Text)
 cmd.Parameters.AddWithValue("@salted", salted.Text)

VS (2017) tells me that hashed and salted are 'not declared' and a yellow light bulb appears to the left with a few suggestions:

ReverendJim.jpg

I am not too surprised about the 'not declared' errors because I don't use hashed.Text or salted.Text anywhere, but I wasn't sure if they referred to my code or to the columns in the database where I do have a hashed (text) column and a salted (text) column.

If you could shed any light on the above, I would be grateful.

Thanks again.

hashed and salted, as their names imply, seem to be booleans.
Don't use such names if they are not.
Your light bulb seems to indicate they are not declared.

Thanks again, ReverendThis is what I now have (below). I haven't been able to access my Web hosting service's server yet, but I am not getting any errors in Visual Studio and the page loads in my browser.

Regards

Public Function CreateRandomSalt() As String

        Dim mix As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+=][}{<>"
        Dim salt As String = ""
        Dim rnd As New Random
        Dim sb As New StringBuilder
        For i As Integer = 1 To 100 'Length of the salt
            Dim x As Integer = rnd.Next(0, mix.Length - 1)
            salt &= (mix.Substring(x, 1))
        Next
        Return salt
    End Function

Public Function Hash512(password As String, salt As String) As String
        Dim convertedToBytes As Byte() = Encoding.UTF8.GetBytes(password & salt)
        Dim hashType As HashAlgorithm = New SHA512Managed()
        Dim hashBytes As Byte() = hashType.ComputeHash(convertedToBytes)
        Dim hashedResult As String = Convert.ToBase64String(hashBytes)
        Return hashedResult
    End Function

Private Sub BtnReg_Click(sender As Object, e As EventArgs) Handles BtnReg.Click 'jmcilchenny suggestion 19.8.2018

        Dim hashedPasswordText As New Label With {.Text = (Hash512(password.Text, CreateRandomSalt))} 'work on this tomorrow 20/8/2018

        Using connection As New OleDbConnection("connectionString")

            Dim Sql As String = "INSERT INTO university (username,strEmail,hashed,salted) VALUES (@username,@strEmail,@hashed,@salted)"
            Dim cmd As New OleDbCommand(Sql)
            cmd.Connection = connection

            cmd.Parameters.AddWithValue("@username", username.Text)
            cmd.Parameters.AddWithValue("@strEmail", strEmail.Text)
            'Dim hashed As String
            Dim hashed As Boolean
            cmd.Parameters.AddWithValue("@hashed", hashed)
            'Dim salted As String
            Dim salted As Boolean
            cmd.Parameters.AddWithValue("@salted", salted)

            connection.Open()
            cmd.ExecuteNonQuery()

        End Using

       End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.