开发者

sql syntax how to do a join?

Im trying to retrieve a path name from my Pictures table the pathname is stored under picturepath in my Pictures table I dont know how to join it on to my current sql syntax it uses the UserID which is set by a session.

And im unsure what goes in the commented line for my image url string?

    using (OdbcCommand cmd = new OdbcCommand("SELECT Wallpostings FROM WallPosting 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"] = "te开发者_运维问答st";
        //div.Style["float"] = "left";

                div.ID = "test";
                Image img = new Image();
                img.ImageUrl = String.Format("{unsure}", reader.GetString(unsure));
                // 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);

sql syntax how to do a join?


img.ImageUrl = string.Format("~/userdata/2/uploadedimage/{0}", (string)reader["TheImageColumn"]);

This will pull the TheImageColumn field from the reader and insert it where {0} is in the string.

SQL

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

You should also not in-line your parameters, use cmd.AddParameter() instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜