Parameterize SQL query(参数化 SQL 查询)
问题描述
许多关于 C# 中的 SQL 参数的帖子,但我仍然缺少一些东西.我没有收到错误消息,但没有插入数据.缺什么?我有名为 fname、lname、address、city、state 和 zip 的文本框.
Many posts about Parameters in SQL with C# but I am still missing something. I am not getting an error message but no data is inserted. What is missing? I have text boxes named fname, lname, address, city, state and zip.
所以我改成了这个,但仍然没有任何反应.
So I changed to this and still nothing happens.
推荐答案
你忘了执行命令 ;)
您也没有使用在方法开始时创建的参数.
you also didn't use the parameters that you created at the beginning of the method.
顺便说一句,不要这样做:
BTW, don't do things like that:
没用,它只是增加了一个新级别的异常,没有添加任何有用的东西.让异常在堆栈中冒泡,直到它到达一个真正有用的 catch 块.
It's useless, it just adds a new level of exception without adding anything useful. Just let the exception bubble up the stack until it reaches a catch block that actually does something useful.
这篇关于参数化 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!