gpt4 book ai didi

c# - sql语法错误?在我的 c# img url 字符串中

转载 作者:行者123 更新时间:2023-11-29 06:17:58 25 4
gpt4 key购买 nike

嗨,我有一个 sql 语法错误:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“[User] u ON u.UserID = wp.UserID LEFT JOIN Pictures p ON p.UserID = u.UserID WHE”附近使用的正确语法

我的代码:

using (OdbcCommand cmd = new OdbcCommand("SELECT wp.WallPostings, p.PicturePath FROM WallPosting wp LEFT JOIN [User] u ON u.UserID = wp.UserID LEFT JOIN Pictures p ON p.UserID = u.UserID WHERE UserID=" + userId + " ORDER BY idWallPosting DESC", cn))
{
//("SELECT wp.WallPostings, p.PicturePath FROM WallPosting wp LEFT JOIN [User] u ON u.UserID = wp.UserID LEFT JOIN Pictures p ON p.UserID = u.UserID WHERE UserID=" + userId + " ORDER BY idWallPosting DESC", cn))
using (OdbcDataReader reader = cmd.ExecuteReader())
{
test1.Controls.Clear();

while (reader.Read())
{
System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.Attributes["class"] = "test";
//div.Style["float"] = "left";

div.ID = "test";
Image img = new Image();
img.ImageUrl = String.Format("{1}", reader.GetString(0));
// this line needs to be represented in sql syntax
img.AlternateText = "Test image";

div.Controls.Add(img);
div.Controls.Add(ParseControl(String.Format("{0}", reader.GetString(0))));
div.Style["clear"] = "both";
test1.Controls.Add(div);

}
}
}
}
}

我的数据库结构:

enter image description here

编辑:

如果我在 mysql 语法中将括号从 User 中取出,则会收到错误:

where 子句中的“UserID”列不明确

重新编辑:

添加wp. WHERE 子句中的 UserID 出现新错误:

索引(从零开始)必须大于或等于零且小于参数列表的大小。

我确定这是由于这一行:

img.ImageUrl = String.Format("{1}", reader.GetString(0));

最佳答案

UserID 存在于多个表中,因此您必须在 WHERE 子句中完全限定它。

          V
... WHERE wp.UserID= ...
^

关于c# - sql语法错误?在我的 c# img url 字符串中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5424680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com