Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Db.Null section for nullable parameters #40860

Open
Tobias-Werner-Recom opened this issue May 13, 2024 · 0 comments
Open

Add Db.Null section for nullable parameters #40860

Tobias-Werner-Recom opened this issue May 13, 2024 · 0 comments

Comments

@Tobias-Werner-Recom
Copy link

Type of issue

Missing information

Description

Add info about Db.Null to the parameter documentation for nullable parameters. The following code throws an exception System.InvalidOperationException: Value must be set..

var command = _db.CreateCommand();
command.CommandText = @"
INSERT INTO users (key, user)
VALUES ($key, $user);
";
command.Parameters.AddWithValue("$key", 1)
command.Parameters.AddWithValue("$user", null)
command.ExecuteNonQuery();

Instead of null one must set System.DBNull. Add this to the documentation.
Corrected code:

var command = _db.CreateCommand();
command.CommandText = @"
INSERT INTO users (key, user)
VALUES ($key, $user);
";
command.Parameters.AddWithValue("$key", 1)
command.Parameters.AddWithValue("$user", System.DBNull.Value)
command.ExecuteNonQuery();

Referenced Issue: dotnet/efcore#19775

Page URL

https://learn.microsoft.com/en-us/dotnet/standard/data/sqlite/parameters

Content source URL

https://github.com/dotnet/docs/blob/main/docs/standard/data/sqlite/parameters.md

Document Version Independent Id

3b84b19f-3d58-5a7d-90a7-0e35f6578fcf

Article author

@ajcvickers

Metadata

  • ID: 0e9c919d-061c-c668-04d2-5f04cfabb587
  • Service: dotnet-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants