Lỗi no value given for one or more required parameter năm 2024

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.

You are not correctly using the OleDbCommand object. Here is a Google Search that will explain how to use it correctly: c# how to use OleDbCommand[^].

Also, as mentioned in your last question, you should never put values into the query string. Doing so opens you to

[].

Here is how to

update

using OleDbCommand:

cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = $"UPDATE {TableName} SET {ColumName} = @value WHERE ID = @id"; cmd.Parameters.AddWithValue("@id", WhatToInsert); cmd.Parameters.AddWithValue("@value", UpdatedInfo); cmd.Connection = connection; connection.Open(); cmd.ExecuteNonQuery(); {

MessageBox.Show("Update Success!");  
cn.Close();`  
}

I think you are using parameters in multiple queries, which are not loading, becasue that parameters table is empty.

Please can you share the sample PBIX file, so investigate this further, in case the above solution does not work.

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

    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

      Lỗi no value given for one or more required parameter năm 2024
      Thread Starter New Member
      Lỗi no value given for one or more required parameter năm 2024

      -

      Re: No value given for one or more required parameters

      Lỗi no value given for one or more required parameter năm 2024
      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

      Lỗi no value given for one or more required parameter năm 2024
      Thread Starter New Member
      Lỗi no value given for one or more required parameter năm 2024

      -

      Re: No value given for one or more required parameters

      Lỗi no value given for one or more required parameter năm 2024
      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: 4969 Size: 22.5 KB](https://https://i0.wp.com/www.vbforums.com/attachment.php?s=b9b68deef2f0f833b4b40b25cbe04ec3&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.