Skip to content

employees snippet: parameterize PopulateSales SQL (follow-up to #12524) - #13072

Merged
gewarren merged 2 commits into
dotnet:mainfrom
krwq:krwq/employees-sql-parameterized
Sep 17, 2026
Merged

gewarren merged 2 commits into
dotnet:mainfrom
krwq:krwq/employees-sql-parameterized

Conversation

@krwq

@krwq krwq commented Sep 16, 2026

Copy link
Copy Markdown
Member

Note

This PR description is AI-generated.

Follow-up to #12524 (review comment gewarren on employees.cs).

Replaces the " + employeeId concatenation in PopulateSales with a SqlParameter. Adds a params SqlParameter[] overload of Populate so the existing parameterless callers keep working.


Internal previews

File Preview link
snippets/csharp/System.Windows.Forms/DataGridView/CellContentClick/employees.cs Learn preview

Build report

Follow-up to PR dotnet#12524 (review comment on employees.cs). The PopulateSales method concatenated the `EmployeeId` cell value into a `SELECT ... WHERE EmployeeId = ` literal, so an untrusted cell value could produce SQL injection. Use a SqlParameter and a matching `@EmployeeId` placeholder instead.

The parameterless `Populate` overload is kept for the existing call sites; a new `params SqlParameter[]` overload backs the parameterized call and forwards to the same connection/adapter path.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ef73ba66-2734-45b8-ab5b-243681f0e519
Copilot AI lite review requested due to automatic review settings September 16, 2026 14:24
@krwq
krwq requested a review from a team as a code owner September 16, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review comments remain, and the query is parameterized.

Pull request overview

Updates the employees WinForms snippet to parameterize the sales query while preserving existing callers.

Changes:

  • Adds a SqlParameter[] overload for Populate.
  • Replaces employee ID SQL concatenation with a parameterized query.
File summaries
File Description
snippets/csharp/System.Windows.Forms/DataGridView/CellContentClick/employees.cs Adds parameter support and secures the sales query.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The employees.cs snippet had no project file, so touching it fails the Snippets 5000 pipeline with CS0234/CS0246 for the System.Windows.Forms and System.Data.SqlClient types it references. Add a net10.0-windows project mirroring the sibling DataGridView\BeginEdit project, plus a System.Data.SqlClient PackageReference.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ef73ba66-2734-45b8-ab5b-243681f0e519
@gewarren
gewarren merged commit bf5df0b into dotnet:main Sep 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants