在文本框內輸入主表ID,單擊Button1葉面顯示子表的相關信息(U_ID,,D_Nm)
主表Buy_M(M_ID,M_Nm)-------各表主鍵是自動增長形式,
子表Buy_D(D_ID,M_ID,U_ID,D_Nm)
通過數組顯示我用的是VS2003!!!!!!!!!我顯示的這樣信息
要修改的物品是:1數量是:1
要修改的物品是:2數量是:2
要修改的物品是:3數量是:3
要修改的物品是:4數量是:4
要修改的物品是:5數量是:5
要修改的物品是:6數量是:6
要修改的物品是:7數量是:7
要修改的物品是:8數量是:8
要修改的物品是:9數量是:9
要修改的物品是:10數量是:10
要修改的物品是:11數量是:11
要修改的物品是:12數量是:12
要修改的物品是:13數量是:13
要修改的物品是:14數量是:14
要修改的物品是:15數量是:15

解决方案 »

  1.   

    我輸入一主表ID,不管明細表是否存在信息都會顯示:
    在文本框內輸入主表ID,單擊Button1葉面顯示子表的相關信息(U_ID,,D_Nm)
    主表Buy_M(M_ID,M_Nm)-------各表主鍵是自動增長形式,
    子表Buy_D(D_ID,M_ID,U_ID,D_Nm)
    通過數組顯示我用的是VS2003!!!!!!!!!我顯示的這樣信息
    要修改的物品是:1數量是:1
    要修改的物品是:2數量是:2
    要修改的物品是:3數量是:3
    要修改的物品是:4數量是:4
    要修改的物品是:5數量是:5
    要修改的物品是:6數量是:6
    要修改的物品是:7數量是:7
    要修改的物品是:8數量是:8
    要修改的物品是:9數量是:9
    要修改的物品是:10數量是:10
    要修改的物品是:11數量是:11
    要修改的物品是:12數量是:12
    要修改的物品是:13數量是:13
    要修改的物品是:14數量是:14
    要修改的物品是:15數量是:15
      
      

  2.   

    //檢測輸入信息
    private static bool Buy_M(String M_ID)
    {
    SqlConnection con=Bll.createCon();
    con.Open();
    SqlCommand cmd=new SqlCommand("select count(*) from Buy_M where M_ID='"+M_ID+"'",con);
    if(Convert.ToInt32(cmd.ExecuteScalar())>0)
    {
    return true;
    }
    else
    {
    return false;
    }
    }Button事件
    private void Button1_Click(object sender, System.EventArgs e)
    {
    SqlConnection con=Bll.createCon();
    con.Open();
    if(TestBuy_M(txtM_ID.Text.Trim()))
    {
    try 
    {
    int[] Tax=new int[5];
    for(int i=0;i<Tax.Length;i++)
    {
    Tax[i]=0;
    }
    string[] name=new string[15];//物品名稱
    string[] value=new string[15];//物品數量
                              

    SqlCommand cmd=new SqlCommand("select U_ID,D_Nm from Buy_D where M_ID='"+txtM_ID.Text+"'",con);//從數據庫中找出數據寫與數組中
    SqlDataReader red=cmd.ExecuteReader();
    int x=0;
            
    while(red.Read())
    {
    for(int i=0;i<=14;i++)//寫到數組中
    {
    name[i]=red["U_ID"].ToString();
    value[i]=red["D_Nm"].ToString();
    }
    x=x+1;
    }
    for(int i=0;i<=14;i++)//寫到數組中
    {
    name[i]=i.ToString();
    value[i]=i.ToString();
    }
    //讀出數據
    for(int j=1;j<=14;j++)
    {
    Response.Write("<br>");
    Response.Write("要修改的物品是:"+name[j].ToString());
    Response.Write("數量是:"+value[j].ToString());
    }
    }

    catch
    {
    Response.Write("錯誤");
    }
    }
    else
    {
    Response.Write("不存在此信息!");
    }
    }
      

  3.   

    是的,我覺得你的問題想的台過復雜化了,你沒必要用數組存取或則顯示那信息
    DataDrid就號//檢測輸入信息
    private static bool Buy_M(String M_ID)
    {
    SqlConnection con=Bll.createCon();
    con.Open();
    SqlCommand cmd=new SqlCommand("select count(*) from Buy_M where M_ID='"+M_ID+"'",con);
    if(Convert.ToInt32(cmd.ExecuteScalar())>0)
    {
    return true;
    }
    else
    {
    return false;
    }
    }Button事件
    private void Button1_Click(object sender, System.EventArgs e)
    {
    SqlConnection con=Bll.createCon();
    con.Open();
    if(TestBuy_M(txtM_ID.Text.Trim()))
    {
    查詢  u_id"再就是DataGrid1綁定,最后做循環顯示
    }
    else
    {
     Response.write("無信息")
    }