private void Page_Load(object sender, System.EventArgs e)
{
  string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data  Source=" + @"C:\
                     Inetpub\wwwroot\wzgy\data\gydb.mdb" + ";";
  OleDbConnection myCn = new OleDbConnection (connstr);
  string sql = "select goods.id as 物资编码,goods.name as 物资名称,
             goods.category_id as 类别,goods.quality as 型号,goods.units as 单位,
   PORT_main.PORT_DATE as 日期,PORT_main.ID1 as 原始凭证,PORT_main.REMARK as 摘要,
     PORT_ITEMS.AMOUNT as 数量 ,PORT_ITEMS.UNITPRICE as 单价,
   PORT_ITEMS.jiner as 金额,PORT_main.IM_EX from goods,PORT_ITEMS,
PORT_main where PORT_ITEMS.GOODS_ID=goods.id and PORT_ITEMS.PORT_ID=PORT_main.ID";  OleDbCommand myComm = new OleDbCommand (sql,myCn );
  myCn.Open ();
  OleDbDataReader reader = myComm.ExecuteReader ();
while (reader.Read ())
{
  if(reader["IM_EX"].ToString()=="I")
  {
   ((Label)Repeater1.FindControl("Label1")).Text=reader["数量"].ToString();
   ((Label)Repeater1.FindControl("Label2")).Text=reader["单价"].ToString();
   ((Label)Repeater1.FindControl("Label3")).Text=reader["金额"].ToString();
   ((Label)Repeater1.FindControl("Label4")).Text="空";
   ((Label)Repeater1.FindControl("Label5")).Text="空";
   ((Label)Repeater1.FindControl("Label6")).Text="空";
  }
else
 {
  ((Label)Repeater1.FindControl("Label1")).Text="空";
  ((Label)Repeater1.FindControl("Label2")).Text="空";
  ((Label)Repeater1.FindControl("Label3")).Text="空";
  ((Label)Repeater1.FindControl("Label4")).Text=reader["数量"].ToString();
  ((Label)Repeater1.FindControl("Label5")).Text=reader["单价"].ToString();
  ((Label)Repeater1.FindControl("Label6")).Text=reader["金额"].ToString();
 }
}
myCn.Close ();
myCn.Dispose ();
myComm.Dispose ();
reader.Close ();
}
试试这样可不可以

解决方案 »

  1.   

    这种可以用DataAdapter来实现,Fill方法Repeater1.FindControl("Label2")).Text=reader["单价"].ToString 这个肯定不行
      

  2.   

    <asp:Repeater id="Repeater1" runat="server">
    <HeaderTemplate>
    <table width="100%" style="font:8pt verdana">
    <tr style="BACKGROUND-COLOR: #ffecd8">
    <th>
    日期</th>
    <th>
    原始凭证</th>
    <th>
    摘要</th>
    <th>
    </th>
    <th>
    收入</th>
    <th>
    </th>
    <th>
    </th>
    <th>
    支出</th>
    <th>
    </th>
    <th>
    </th>
    <th>
    结余</th>
    <th>
    </th>
    </tr>
    <tr style="BACKGROUND-COLOR: #ffecd8">
    <th>
    </th>
    <th>
    </th>
    <th>
    </th>
    <th>
    数量</th>
    <th>
    单价</th>
    <th>
    金额</th>
    <th>
    数量</th>
    <th>
    单价</th>
    <th>
    金额</th>
    <th>
    数量</th>
    <th>
    单价</th>
    <th>
    金额</th>
    </tr>
    </table>
    </HeaderTemplate>
    <ItemTemplate>
    <TABLE id="Table1" style="Z-INDEX: 101; LEFT: 135px; POSITION: absolute; TOP: 211px" cellSpacing="1" cellPadding="1" width="300" border="1">
    <TR>
    <Th>
    <asp:Label id="Label1" runat="server">
    <%# DataBinder.Eval(Container.DataItem,"数量")%>
    </asp:Label></Th>
    <Th>
    <asp:Label id="Label2" runat="server">
    <%# DataBinder.Eval(Container.DataItem,"单价")%>
    </asp:Label></Th>
    <Th>
    <asp:Label id="Label3" runat="server">
    <%# DataBinder.Eval(Container.DataItem,"金额")%>
    </asp:Label></Th>
    <Th>
    <asp:Label id="Label4" runat="server">
    <%# DataBinder.Eval(Container.DataItem,"数量2")%>
    </asp:Label></Th>
    <Th>
    <asp:Label id="Label5" runat="server">
    <%# DataBinder.Eval(Container.DataItem,"单价2")%>
    </asp:Label></Th>
    <Th>
    <asp:Label id="Label6" runat="server">
    <%# DataBinder.Eval(Container.DataItem,"金额2")%>
    </asp:Label></Th>
    </TR>
    </table>
    </ItemTemplate>
    <FooterTemplate>
    </table></TABLE>
    </FooterTemplate>
    </asp:Repeater>
    程序:
    private void Page_Load(object sender, System.EventArgs e)
    {
    string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"C:\Inetpub\wwwroot\wzgy\data\gydb.mdb" + ";";
    OleDbConnection myCn = new OleDbConnection (connstr);
    string sql = "select goods.id as 物资编码,goods.name as 物资名称,goods.category_id as 类别,goods.quality as 型号,goods.units as 单位,PORT_main.PORT_DATE as 日期,PORT_main.ID1 as 原始凭证,PORT_main.REMARK as 摘要,PORT_ITEMS.AMOUNT as 数量,PORT_ITEMS.AMOUNT as 数量2, PORT_ITEMS.UNITPRICE as 单价,PORT_ITEMS.UNITPRICE as 单价2,PORT_ITEMS.jiner as 金额,PORT_ITEMS.jiner as 金额2,PORT_main.IM_EX from goods,PORT_ITEMS,PORT_main where PORT_ITEMS.GOODS_ID=goods.id and PORT_ITEMS.PORT_ID=PORT_main.ID";
    OleDbDataAdapter adp = new OleDbDataAdapter(sql,myCn);
    DataSet ds = new DataSet();
    adp.Fill(ds,"goods");

    for(int i=0;i<ds.Tables["goods"].Rows.Count;i++)
    {
    if(ds.Tables["goods"].Rows[i]["IM_EX"].ToString()=="I")
    {
    ds.Tables["goods"].Rows[i]["数量1"]="空";
    ds.Tables["goods"].Rows[i]["单价1"]="空";
    ds.Tables["goods"].Rows[i]["金额1"]="空";
    }
    else
    {
    ds.Tables["goods"].Rows[i]["数量"]="空";
    ds.Tables["goods"].Rows[i]["单价"]="空";
    ds.Tables["goods"].Rows[i]["金额"]="空";
    }
    }

        Repeater1.DataSource = ds.Tables["goods"].DefaultView;
    Repeater1.DataBind();

    }
      

  3.   

    错了,是这样:
    private void Page_Load(object sender, System.EventArgs e)
    {
    string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"C:\Inetpub\wwwroot\wzgy\data\gydb.mdb" + ";";
    OleDbConnection myCn = new OleDbConnection (connstr);
    string sql = "select goods.id as 物资编码,goods.name as 物资名称,goods.category_id as 类别,goods.quality as 型号,goods.units as 单位,PORT_main.PORT_DATE as 日期,PORT_main.ID1 as 原始凭证,PORT_main.REMARK as 摘要,PORT_ITEMS.AMOUNT as 数量,PORT_ITEMS.AMOUNT as 数量2, PORT_ITEMS.UNITPRICE as 单价,PORT_ITEMS.UNITPRICE as 单价2,PORT_ITEMS.jiner as 金额,PORT_ITEMS.jiner as 金额2,PORT_main.IM_EX from goods,PORT_ITEMS,PORT_main where PORT_ITEMS.GOODS_ID=goods.id and PORT_ITEMS.PORT_ID=PORT_main.ID";
    OleDbDataAdapter adp = new OleDbDataAdapter(sql,myCn);
    DataSet ds = new DataSet();
    adp.Fill(ds,"goods");

    for(int i=0;i<ds.Tables["goods"].Rows.Count;i++)
    {
    if(ds.Tables["goods"].Rows[i]["IM_EX"].ToString()=="I")
    {
    ds.Tables["goods"].Rows[i]["数量2"]="空";
    ds.Tables["goods"].Rows[i]["单价2"]="空";
    ds.Tables["goods"].Rows[i]["金额2"]="空";
    }
    else
    {
    ds.Tables["goods"].Rows[i]["数量"]="空";
    ds.Tables["goods"].Rows[i]["单价"]="空";
    ds.Tables["goods"].Rows[i]["金额"]="空";
    }
    }

    Repeater1.DataSource = ds.Tables["goods"].DefaultView;
     Repeater1.DataBind();

    }
      

  4.   

    “/wzgy”应用程序中的服务器错误。
    --------------------------------------------------------------------------------列“数量2”不属于表 goods。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentException: 列“数量2”不属于表 goods。