0

Hello community I have a question regarding how to make the form push to the database and insert the data provided in the table what happens is that according to me I already have the correct insert and I need to run it so that when I enter the section of new User asks me to fill out a form but when I try to enter that section I get the following: **System.Data.SqlClient.SqlException: 'The parameterized query '(@UserN nvarchar(4000),@Password nvarchar(4000),@Role nvarchar(4' expects the parameter '@UserN', which was not supplied.' ** from what I read of the error it tells me that it is waiting for the parameter but it never receives something which does not happen because it does not even load the view according to my theory is that it loads the controller before the view loads and does not let me do the process correctly then I would like to know how I can make this not happen I would like that this function of insert in the table would happen after all the data is filled inside the form I do not know if the onclick() event also works in VB I leave my code to know what is wrong

        Dim Nombre As String
        Dim Puesto As String
        Dim role As String

        ' Obtener los valores del formulario
        UserN = Request.Form("userN")
        password = Request.Form("password")
        role = Request.Form("Role")
        Nombre = Request.Form("Nombre")
        Puesto = Request.Form("Puesto")

        ' Query para insertar los valores en la base de datos
        Dim query As String = "INSERT INTO IntranetSecurity (UserN, Password, Role, Nombre, Puesto) VALUES (@UserN, @Password, @Role, @Nombre, @Puesto)"
        Using command As New SqlCommand(query, cnn)
            ' Agregar parámetros para prevenir inyección SQL y asegurar la integridad de los datos
            command.Parameters.AddWithValue("@UserN", UserN)
            command.Parameters.AddWithValue("@Password", password)
            command.Parameters.AddWithValue("@Role", role)
            command.Parameters.AddWithValue("@Nombre", Nombre)
            command.Parameters.AddWithValue("@Puesto", Puesto)

            ' Abrir la conexión y ejecutar el comando
            cnn.Open()
            command.ExecuteNonQuery()

        End Using
        Return View()``` 
4
  • The first thing you need to do is debug your code and determine what values you're assigning to the command parameters. I suspect that it's Nothing. Commented Apr 17, 2024 at 14:07
  • yes, because when I click to go to the view that has the controller to do that I get the error before I can even put in any data. Commented Apr 17, 2024 at 14:10
  • Your comment makes little sense. The error message looks like it would be generated where you call ExecuteNonQuery, which would be well after you should have entered the data. I'm also not sure why you would be using Request.Form in a controller action. Why haven't you got a model with the appropriate properties? Commented Apr 18, 2024 at 2:16
  • Cause its a form to create a new user so i believe that this is the correct form you can insert the information in the database Commented Apr 18, 2024 at 13:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.