必须定义参数"@myLeft" [英] Parameter '@myLeft' must be defined

查看:99
本文介绍了必须定义参数"@myLeft"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与已经回答的问题非常相似,但还没有.我需要一些帮助来解决这个问题.

My question is quite similar to already answered ones but yet not. I'd like some help sorting this out.

我正在尝试将数据添加到数据库表中,但出现标题错误.这是我的MySQL代码:

I'm trying to add data to a database table but I get keeping the titled error. Here's my MySQL-code:

Dim objCmdInsert As New MySqlCommand("LOCK TABLE threads WRITE;SET @myLeft := lft;SELECT @myLeft FROM threads WHERE threadid = '" & Request.QueryString("id") & "';UPDATE threads SET rgt = rgt + 2 WHERE rgt > @myLeft;UPDATE threads SET lft = lft + 2 WHERE lft > @myLeft;INSERT INTO threads(threadid, category, userid, ipaddress, section, subject, summary, body, tags, postedat, updatedat, rating, status, lft, rgt) VALUES(?threadid, ?category, ?userid, ?ipaddress, ?section, ?subject, ?summary, ?body, ?tags, ?postedat, ?updatedat, ?rating, ?status, @myLeft + 1, @myLeft + 2);UNLOCK TABLES;", objConn)

objCmdInsert.Parameters.Add("?threadid", MySqlDbType.VarChar, 36).Value = Guid.NewGuid.ToString()
objCmdInsert.Parameters.Add("?category", MySqlDbType.VarChar, 36).Value = "articlecomment"
objCmdInsert.Parameters.Add("?ipaddress", MySqlDbType.VarChar, 20).Value = HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
objCmdInsert.Parameters.Add("?section", MySqlDbType.VarChar, 36).Value = DBNull.Value
objCmdInsert.Parameters.Add("?userid", MySqlDbType.VarChar, 36).Value = GetStubs.GetUserGuid(HttpContext.Current.User.Identity.Name.ToString())
objCmdInsert.Parameters.Add("?subject", MySqlDbType.VarChar, 500).Value = DBNull.Value
objCmdInsert.Parameters.Add("?summary", MySqlDbType.Text).Value = DBNull.Value
objCmdInsert.Parameters.Add("?body", MySqlDbType.Text).Value = CommentBody.Text
objCmdInsert.Parameters.Add("?tags", MySqlDbType.VarChar, 500).Value = DBNull.Value
objCmdInsert.Parameters.Add("?postedat", MySqlDbType.DateTime).Value = DateTime.Now.ToString()
objCmdInsert.Parameters.Add("?updatedat", MySqlDbType.DateTime).Value = DateTime.Now.ToString()
objCmdInsert.Parameters.Add("?rating", MySqlDbType.Int32).Value = "0"
objCmdInsert.Parameters.Add("?status", MySqlDbType.VarChar, 200).Value = "Open"

我在做什么错了?

推荐答案

我通过在Google上广泛搜索MySQL中未定义的参数,找到了解决此问题的方法.本文( MySql.Data. MySqlClient.MySqlException:必须定义参数'@id')涵盖了问题的基础.据我了解,与连接器的升级有关.

I found the solution to this problem by making an extensive Google search for undefined parameters in MySQL. This article (MySql.Data.MySqlClient.MySqlException: Parameter ‘@id’ must be defined) covers the basics of the problem. It's as far as I understand related to an upgrade of the connector.

您需要在连接字符串中添加Allow User Variables=True才能使用自定义变量.一个同样棘手的问题的非常简单的解决方案. ;)

You need to add Allow User Variables=True in the connection string in order to use custom variables. Pretty simple solution to an equally tough problem. ;)

这篇关于必须定义参数"@myLeft"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆