C# 嗨,这只是一个文本框,设置为多行。所以我不认为它会起作用。好吧,我会相应地修改答案,但最好使用网格我明白,但我的目的是让用户根据选择得到一份成分列表。然后,他们可以手工编辑文本并将其导出。。。这是它工作的功能,但是它只检索1行,而它应该检索14行。不管你做

C# 嗨,这只是一个文本框,设置为多行。所以我不认为它会起作用。好吧,我会相应地修改答案,但最好使用网格我明白,但我的目的是让用户根据选择得到一份成分列表。然后,他们可以手工编辑文本并将其导出。。。这是它工作的功能,但是它只检索1行,而它应该检索14行。不管你做,c#,sql,asp.net,C#,Sql,Asp.net,嗨,这只是一个文本框,设置为多行。所以我不认为它会起作用。好吧,我会相应地修改答案,但最好使用网格我明白,但我的目的是让用户根据选择得到一份成分列表。然后,他们可以手工编辑文本并将其导出。。。这是它工作的功能,但是它只检索1行,而它应该检索14行。不管你做了什么,它只需要以某种方式循环并获取它们。感谢you@SamGhatak是的,if是多余的,格式字符串可以扩展,但这需要提问者最终确定并符合具体要求。我的帖子只是想让他开始解决方案x)@SamGhatak是的,if是多余的,格式字符串可以扩展,



嗨,这只是一个文本框,设置为多行。所以我不认为它会起作用。好吧,我会相应地修改答案,但最好使用网格我明白,但我的目的是让用户根据选择得到一份成分列表。然后,他们可以手工编辑文本并将其导出。。。这是它工作的功能,但是它只检索1行,而它应该检索14行。不管你做了什么,它只需要以某种方式循环并获取它们。感谢you@SamGhatak是的,
if
是多余的,格式字符串可以扩展,但这需要提问者最终确定并符合具体要求。我的帖子只是想让他开始解决方案x)@SamGhatak是的,
if
是多余的,格式字符串可以扩展,但这需要提问者最终确定并符合具体要求。我的帖子只是想让他开始了解解决方案x)“object”不包含“ItemArray”的定义,并且找不到接受“object”类型第一个参数的扩展方法“ItemArray”(是否缺少using指令或程序集引用?@DonaldBury:有趣。您可能需要使用“DataRow”而不是“var row”或类似的东西。我已经很长时间没有使用旧的ADO对象了,强类型从来都不是他们的拿手好戏。我使用了dt.Rows[0].ItemArray并使其正常工作。现在我又遇到了另一个问题。它检索同一行,但检索了14次。14倍于14种成分items@DonaldBury:听起来你的查询返回了14条记录。是的,但它只显示了最上面的行14次。它没有显示14个单独的行“object”不包含“ItemArray”的定义,并且找不到接受“object”类型的第一个参数的扩展方法“ItemArray”(是否缺少using指令或程序集引用?@DonaldBury:有趣。您可能需要使用“DataRow”而不是“var row”或类似的东西。我已经很长时间没有使用旧的ADO对象了,强类型从来都不是他们的拿手好戏。我使用了dt.Rows[0].ItemArray并使其正常工作。现在我又遇到了另一个问题。它检索同一行,但检索了14次。14倍于14种成分items@DonaldBury:听起来你的查询返回了14条记录。是的,但它只显示了最上面的行14次。它没有显示14个单独的行
orange | 1
apple  | 5
kiwi   | 2
steak | 1
steak | 1
steak | 1
protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["New"] != null)
            {               
                                if (Session["Basket"] != null)
            {
                ShoppingBasket.Visible = true;
                redPnl.Visible = false;
                RecipeID.Text += Session["Basket"].ToString();

                SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0; AttachDbFilename=C:\Users\Donald\Documents\Visual Studio 2013\Projects\DesktopApplication\DesktopApplication\Student_CB.mdf ;Integrated Security=True");
                con.Open();

                SqlDataAdapter sda = new SqlDataAdapter("Select * From Ingredient Where Recipe_ID=@RecipeID", con);
                sda.SelectCommand.Parameters.Add("@RecipeID", SqlDbType.VarChar).Value = RecipeID.Text;
                DataTable dt = new DataTable();
                sda.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    foreach (var row in dt.Rows)
                    {
                        IngredientsList.Text += dt.Rows[0].ItemArray[0].ToString() + " | " + dt.Rows[0].ItemArray[1].ToString() + " | " + dt.Rows[0].ItemArray[2].ToString() + Environment.NewLine;
                    }
                }
            }
protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["New"] != null)
            {               
                if (Session["Basket"] != null)
                {
                    ShoppingBasket.Visible = true;                    
                    redPnl.Visible = false;                   
                    RecipeID.Text += Session["Basket"].ToString();

                    SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0; AttachDbFilename=C:\Users\Donald\Documents\Visual Studio 2013\Projects\DesktopApplication\DesktopApplication\Student_CB.mdf ;Integrated Security=True");
                    con.Open();

                    SqlDataAdapter sda = new SqlDataAdapter("Select Ingredient_Name, Ingredient_Amount From Ingredient Where Recipe_ID=@RecipeID", con);
                    sda.SelectCommand.Parameters.Add("@RecipeID", SqlDbType.VarChar).Value = RecipeID.Text;
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    IngredientsList.Text = string.Empty;
                    for (int i = 0; i<dt.Rows.Count ;i++)
                    {
                        IngredientsList.Text += dt.Rows[i].ItemArray[0].ToString();
                        IngredientsList[i].Text += " | " + dt.Rows[i].ItemArray[1].ToString() + Enviornment.NewLine;
                        //dt.Clear(); :EDITED
                    }
                    dt.Clear();
                }

            }

        }
if (dt.Rows.Count > 0)
{
    foreach(var row in dt.Rows){
        IngredientsList.Text.Append(String.Format("{0}|{1}",row.ItemArray[0], row.ItemArray[1]));
    }
    dt.Clear();
}
if (dt.Rows.Count > 0)
{
    IngredientsList.Text = dt.Rows[0].ItemArray[0].ToString();
    IngredientsList.Text = dt.Rows[0].ItemArray[1].ToString();
    dt.Clear();
}
if (dt.Rows.Count > 0)
{
    foreach (DataRow row in dt.Rows)
    {
        IngredientsList.Text += row.ItemArray[0].ToString() + " | " + row.ItemArray[1].ToString() + Environment.NewLine;
    }
}
orange | 1
apple | 5
kiwi | 2
row.ItemArray[0].ToString()
row.ItemArray[0].ToString().PadRight(6)