嗨相關的字符串的問題,當我在idWallPosting
在我下面的代碼添加到我的select語句即時得到一個sqlsyntax錯誤:SQL snytax錯誤,並sqlsyntax
using (OdbcCommand cmd = new OdbcCommand("SELECT idWallPosting, 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 wp.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.ID = String.Format("{0}", reader.GetString(2));
// this line is responsible, problem here and my sqlsntax, im trying to set the SELECT idWallPosting for the div ID
Image img = new Image();
img.ImageUrl = String.Format("{0}", reader.GetString(1));
img.AlternateText = "Test image";
div.Controls.Add(img);
div.Controls.Add(ParseControl(String.Format("   " + "{0}", reader.GetString(0))));
div.Attributes.Add("onclick", "return confirm_delete();");
div.Style["clear"] = "both";
test1.Controls.Add(div);
}
}
}
我的數據庫看起來是這樣的:
在我的代碼即時嘗試將div.ID設置爲我的WallPosting表中的當前idWallPosting,所以即時通訊也不知道我有沒有更正。
編輯:
錯誤:
Unable to cast object of type 'System.Int32' to type 'System.String'.
相關的這條線,我認爲:
div.ID = String.Format("{0}", reader.GetString(2));
讓我們開始吧,在idwallposting之後是否缺少逗號? – nycdan 2011-03-30 17:14:10