English 中文(简体)
ql syntax 问题或代码问题? “Index在阵列之外
原标题:sql syntax problem and or code problem? "Index was outside the bounds of the array."

我不得不对我的数据库做一些改进,我确实认为:

“数据库”/

但是,我不得不改变《隔离墙》:

“WallPosting”/

现在,我的问题是如何确定我的yn子,以便我的代码再次奏效。

朋友 用户信息数据库与另一个用户信息数据库有关,用户信息明显不同,但我不知道如何同时展示来自不同用户的隔离墙。

我的法典创造了一个动态的圆环,使“ID =”能够使用并输入“挂图”的挂图,它掌握了有关使用线的信息,并应用了与这种使用有关的图像,这是否可以用斜线加以改变? 或者我以某种方式ey倒了吗? 我只想看到,我是否能够获得有人居住的隔离墙口供。

我的法典:

public partial class UserProfileWall : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            //It is a postback so check if it was by div click (NOT WORKING because the javascript isnt posting back)
            string target = Request["__EVENTTARGET"];
            if (target == "DivClicked")
            {
                string id = Request["__EVENTARGUMENT"];
                //Call my delete function passing record id
                using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;"))
                {
                    cn.Open();
                    using (OdbcCommand cmd = new OdbcCommand("DELETE FROM WallPosting WHERE idWallPosting="+id, cn))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
        string theUserId = Session["UserID"].ToString();
        PopulateWallPosts(theUserId);
    }
    private void PopulateWallPosts(string userId)
    {
        using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;"))
        {
            cn.Open();
            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(0));
                        string id = Convert.ToString(div.ID);
                        //store the div id as a string
                        Image img = new Image();
                        img.ImageUrl = String.Format("{0}", reader.GetString(2));
                        img.AlternateText = "Test image";

                        div.Controls.Add(img);
                        div.Controls.Add(ParseControl(String.Format("&nbsp&nbsp " + "{0}", reader.GetString(1))));
                        div.Attributes.Add("onclick", "confirm_delete(" + id + ");");
                        // send the div id to javascript
                        div.Style["clear"] = "both";
                        test1.Controls.Add(div);
                    }
                }
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string theUserId = Session["UserID"].ToString();
        using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;"))
        {
            cn.Open();
            using (OdbcCommand cmd = new OdbcCommand("INSERT INTO WallPosting (UserID, Wallpostings) VALUES (" + theUserId + ",  " + TextBox1.Text + " )", cn))
            {
                cmd.ExecuteNonQuery();
            }
        }
        PopulateWallPosts(theUserId);
    }
}

我发现错误:指数超出了阵列的界限。

using (OdbcCommand cmd = new OdbcCommand("SELECT wp.WallPostings, p.PicturePath FROM WallPosting wp INNER JOIN User u ON u.UserID = wp.FriendUserID INNER JOIN Pictures p ON p.UserID = u.UserID WHERE wp.UserID=" + userId + " ORDER BY idWallPosting DESC", cn))
最佳回答

Always store who posted it, even if the owner of the wall did it herself. This will simplify the sql for you.

SELECT wp.WallPostings, p.PicturePath 
FROM WallPosting wp 
INNER JOIN [User] u ON u.UserID = wp.PostedByUserID 
INNER JOIN Pictures p ON p.UserID = u.UserID 
WHERE wp.UserID=" + userId + " 
ORDER BY idWallPosting DESC

如果是1到1,为什么在单独表格中出现情况?

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签