为什么我的参数化 ADO 查询出现错误?
Dim txtFName As TextBox = CType(Wizard1.FindControl("txtFName"), TextBox)
Dim txtLName As TextBox = CType(Wizard1.FindControl("txtLName"), TextBox)
Dim MyDbConnection As New SqlConnection(ConfigurationManager.ConnectionStrings.Item("Journeyeast Connection String").ToString)
MyDbConnection.Open()
Dim SQL = "INSERT INTO Registration(FName, LName) VALUES (@FName, @LName)"
Dim MySqlCommand As New SqlCommand(SQL, MyDbConnection)
MySqlCommand.Parameters.Add("@FName", SqlDbType.NChar, 10, txtFName.Text)
MySqlCommand.Parameters.Add("@LName", SqlDbType.NChar, 10, txtLName.Text)
MySqlCommand.ExecuteNonQuery()
我收到以下错误:
参数化查询“(@FName nchar(10),@LName nchar(10))INSERT INTO Registration(FNam”需要参数“@FName”,但未提供该参数。
我做错了什么?
顺便说一句,我知道 nchar(10)
对于名字和姓氏来说不是一个好的选择。
Dim txtFName As TextBox = CType(Wizard1.FindControl("txtFName"), TextBox)
Dim txtLName As TextBox = CType(Wizard1.FindControl("txtLName"), TextBox)
Dim MyDbConnection As New SqlConnection(ConfigurationManager.ConnectionStrings.Item("Journeyeast Connection String").ToString)
MyDbConnection.Open()
Dim SQL = "INSERT INTO Registration(FName, LName) VALUES (@FName, @LName)"
Dim MySqlCommand As New SqlCommand(SQL, MyDbConnection)
MySqlCommand.Parameters.Add("@FName", SqlDbType.NChar, 10, txtFName.Text)
MySqlCommand.Parameters.Add("@LName", SqlDbType.NChar, 10, txtLName.Text)
MySqlCommand.ExecuteNonQuery()
I am getting the following error:
The parameterized query '(@FName nchar(10),@LName nchar(10))INSERT INTO Registration(FNam' expects the parameter '@FName', which was not supplied.
What am I doing wrong?
BTW, I know nchar(10)
is not a good choice for first and last name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您还没有提供参数值。
看一下:
编辑:
Because you haven't supplied parameter values.
Take a look at:
EDIT: