修复列数据类型和重复列问题

时间:2010-11-30 18:22:17

标签: asp.net sql vb.net

这是我的程序完整代码,唯一的问题是我想修复我的gridview中显示的小数位数。问题是如果我在asp端执行此操作,列的位置将被抛出并且列是重复的。我想如果我只是在asp方面重新制作表,它只会工作问题是如果我删除了特定列的SQL,那么asp侧列无法获取数据。

 Imports System.Data.Sql
    Imports System.Data.SqlClient
    Imports System.Data
    Partial Class _Default
        Inherits System.Web.UI.Page
        Public saocmd As New SqlCommand()
        Public saoda As New SqlDataAdapter(saocmd)

        Dim saods As New DataSet

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            saocmd.Connection = conn
            conn.Open()

            Dim ds As New DataSet

            saocmd.CommandText = "SELECT B603SalesAsOFMASTER.SDESCR, B603SalesAsOFMASTER.DYYYY, B603SalesAsOFMASTER.AsOFSales, B603SalesAsOFMASTER.ASOFPAX, B603SalesAsOFMASTER.YESales, B603SalesAsOFMASTER.YEPAX, B603SalesAsOFMASTER.PCTofSales, B601SalesAsOF.Sales AS [Current Sales], B601SalesAsOF.PAX AS [Current PAX] FROM B603SalesAsOFMASTER INNER JOIN B601SalesAsOF ON B603SalesAsOFMASTER.SDESCR = B601SalesAsOF.SDESCR WHERE (B603SalesAsOFMASTER.DYYYY = '2008') AND (B601SalesAsOF.DYYYY = '2010')"
            saoda.Fill(saods, "salesasoftable")

            Dim pctofpax As New DataColumn
            pctofpax = New DataColumn("PCTPAX1", GetType(Decimal))
            pctofpax.Expression = "[ASOFPAX] / [YEPAX]"
            saods.Tables("salesasoftable").Columns.Add(pctofpax)

            Dim avgppax As New DataColumn
            avgppax = New DataColumn("AVG PAX", GetType(Double))
            avgppax.Expression = "[Current Sales] / [Current PAX]"
            saods.Tables("salesasoftable").Columns.Add(avgppax)

            Dim projectedye As New DataColumn
            projectedye = New DataColumn("Projected YE Sales", GetType(Double))
            projectedye.Expression = "[Current Sales] / PCTofSales"
            saods.Tables("salesasoftable").Columns.Add(projectedye)

            Dim projectedyep As New DataColumn
            projectedyep = New DataColumn("Projected YE PAX", GetType(Double))
            projectedyep.Expression = "[Current PAX] / PCTPAX1"
            saods.Tables("salesasoftable").Columns.Add(projectedyep)



            GridView1.DataSource = saods

            GridView1.DataBind()

            saoda.FillSchema(saods, SchemaType.Mapped)

            conn.Close()
        End Sub
    End Class

ASP Side



     <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>

            <span lang="en-us">Sales As Of Analysis</span><br />
           <asp:GridView ID="GridView1" runat="server" BackColor="White" 
                  BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
                  GridLines="Vertical">
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <Columns>
             <asp:Boundfield DataField="SDESCR" 
                             HeaderText="Regions">
             </asp:Boundfield>

             <asp:Boundfield DataField="DYYYY" 
                             HeaderText="DYYYY">
             </asp:Boundfield>


            <asp:Boundfield DataField="asofsales" 
                             HeaderText="As Of Sales" 
                             DataFormatString="{0:c}">
            </asp:Boundfield>
        </Columns>
    </asp:GridView>

        </div>
        </form>
    </body>
    </html>

1 个答案:

答案 0 :(得分:4)

答案是关闭自动生成列!