Lỗi no value given for one or more required

Microsoft Access databases must be installed on the same system as the web application. This is a Microsoft Access restriction.

  • The folder containing the database and the database file[s] themselves must be read and write enabled.
  • The database folder must also be accessible by the user configured for the Virtual Directory. This is generally the ASPNET user. For starters, don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. When you concatenate strings, you cause problems because SQL receives commands like: SELECT FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command: SELECT FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;

    Which SQL sees as three separate commands: SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT DROP TABLE MyTable; A perfectly valid "delete the table" command And everything else is a comment. So it does: selects any matching rows, deletes the table from the DB, and ignores anything else. So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you? Then, look at your command: it's a bad idea to not specify the column names to insert into, because unless your table has only a single column, SQL will try to insert your values starting from the first column [which is normally an ID column, often IDENTITY which means you can't write to it anyway]. INSERT INTO MyTable MyColumn1, MyColumn2 VALUES [@ValueForColumn1, @ValueForColumn2] From your error message, you have multiple columns and they cannot be NULL so SQL expects a value to be provided. As for your problem, does the laptop have MS Access or the runtime engine installed on it? When does the error occur. On startup or sometime after?

  • Mar 21st, 2020, 12:55 PM

    Re: No value given for one or more required parameters
    Unfortunately the error message you are getting is one that occurs for many related issues - it basically means "there is something wrong with the SQL statement and/or parameters" [with the parameters being unlikely, and in this case also irrelevant]

In this case the SQL statement is in the variable query. I would recommend initially removing the ; from the end of the line, as it isn't needed, and removing it might fix the issue.

If that doesn't solve it, to find out what is causing the issue temporarily comment out the "Try" line, and the Catch section. Then when the error occurs, I would expect the issue to occur on the ExecuteReader[] line. Add the query variable as a Watch to make sure that it contains something valid. If you can't spot the issue yourself, copy+paste the value here from the Watch window.

-
  • Mar 21st, 2020, 01:50 PM

    Thread Starter New Member

    -

    Re: No value given for one or more required parameters

    Originally Posted by wes4dbt

When you post code always put it between code tags so it will keep its formatting, on the tool bar select either "VB" or "#".

As for your problem, does the laptop have MS Access or the runtime engine installed on it? When does the error occur. On startup or sometime after?

Yeah it has MS Access installed. The error occurs once the station has been entered into the input box and Ok is clicked

-
  • Mar 21st, 2020, 03:42 PM

    Thread Starter New Member

    -

    Re: No value given for one or more required parameters

    Originally Posted by si_the_geek

Unfortunately the error message you are getting is one that occurs for many related issues - it basically means "there is something wrong with the SQL statement and/or parameters" [with the parameters being unlikely, and in this case also irrelevant]

In this case the SQL statement is in the variable query. I would recommend initially removing the ; from the end of the line, as it isn't needed, and removing it might fix the issue.

If that doesn't solve it, to find out what is causing the issue temporarily comment out the "Try" line, and the Catch section. Then when the error occurs, I would expect the issue to occur on the ExecuteReader[] line. Add the query variable as a Watch to make sure that it contains something valid. If you can't spot the issue yourself, copy+paste the value here from the Watch window.

![Name: Try.jpg Views: 3795 Size: 22.5 KB][////i0.wp.com/www.vbforums.com/attachment.php?s=11ee39aeef8a8353c6e15f2912a4bc65&attachmentid=175475&d=1584823285] That's what appears I'm not too sure what it means

  • Mar 21st, 2020, 03:46 PM

    Re: No value given for one or more required parameters

    When the exception occurs, take a look at command.CommandText. Paste the contents of that variable into a reply so that we can see it. Something is wrong with that commandtext, though exactly what it is can be pretty hard to spot. Make sure that all of the fields and tables are correct and spelled correctly.

Chủ Đề