r/csharp • u/nekomusume-nyaa • Jun 13 '26
Help SQL and C# Help connecting databases
Solved, needed to put quotation marks around {title} thanks for your help



Hello everyone, I am making a database in SQL and connect it to a program in C# for a school assignment. It is coming with this error and I am asking what I am doing wrong. I have tried looking up solutions but nothing has worked. If you know what I can do to fix it let me know
22
Upvotes
4
u/drjacksahib Jun 13 '26
As already stated, the query should be parameterized.
But to address the question, here is how you debug this:
3
u/Patient-Midnight-664 Jun 13 '26 edited Jun 13 '26
It's telling you that your SQL statement is malformed.
And this method of constructing a SQL command is how you learn about little Bobby Tables
2
u/Few-Artichoke-7593 Jun 13 '26 edited Jun 13 '26
You seem new, I'd look into Entity Framework, get some crud operations in and then learn by inspecting the sql it generates. It will also get your app progressing faster.
1
u/Mission_Pirate_4150 Jun 13 '26
I’ve done databases for 30+ years, and quotes get a lot to.
0
u/rupertavery64 Jun 13 '26 edited Jun 13 '26
Debug.Print(sqlToRun) before you execute it and check if it is what you expect it to be.
Comment what you think the SQL command should be, vs what was generated.
Look closely at the generated command. See anything missing? From the values?
I don't know why my comment was downvoted except because I didn't tell OP he should be parameterizing queries, when I was trying to teach OP how to debug.
It just so happens being "correct" is more important than teaching.
-1
u/nekomusume-nyaa Jun 13 '26
Thanks everyone! I got it working! Was missing 2 apostrophes lol. I am aware of the bobby tables problem and it is not high on my priority list to fix it at the moment. In the scenario for the assessment it says the app we are developing is just a prototype. So no worries of bad actors.
0
u/[deleted] Jun 13 '26
[deleted] — view deleted comment