so I have updated a table for a class project (given to me that had work completed on it from previous students) and am now unable to view the data for the income statement page that it is used for. The columns I renamed/updated were previously 2012-2015 and now are 2020-2023.[enter image description here](https://i.sstatic.net/51flQsFH.png)
enter image description here
aspx file snippet
<h5>Select A Company</h5>
<div class="row-fluid">
<div class="span6">
<asp:SqlDataSource ID="SqlDSCompany" runat="server" ConnectionString="<%$ ConnectionStrings:CPAConnectionString %>" SelectCommand="SELECT [CompanyName] FROM [Company]"></asp:SqlDataSource>
<asp:DropDownList ID="DDLCompany" runat="server" DataSourceID="SqlDSCompany" DataTextField="CompanyName" DataValueField="CompanyName" AppendDataBoundItems="True" AutoPostBack="true" OnSelectedIndexChanged="DDLCompany_SelectedIndexChanged">
<asp:ListItem Value="" Text="Select Company"></asp:ListItem>
</asp:DropDownList>
</div>
</div>
<div class="container">
<table class="default">
<tr>
<td class="tdTitle" width="25%">
<h4><b>Period Ending</b></h4>
</td>
<!--<td width="14%">2019</td>-->
<td width="14%">2020</td>
<td width="14%">2021</td>
<td width="14%">2022</td>
<td width="14%">2023</td>
</tr>
</table>
<table class="default">
<tr>
<td class="tdTitle" width="25%">
<h5><b>Total Revenue:</b></h5>
</td>
<td width="14%">
<asp:Label ID="lblTotalRevenue1" runat="server"></asp:Label></td>
<td width="14%">
<asp:Label ID="lblTotalRevenue2" runat="server"></asp:Label></td>
<td width="14%">
<asp:Label ID="lblTotalRevenue3" runat="server"></asp:Label></td>
<td width="14%">
<asp:Label ID="lblTotalRevenue4" runat="server"></asp:Label></td>
</tr>
</table>
code-behind
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO`
Partial Class IncomeStatement
Inherits System.Web.UI.Page
Dim query As String
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadNoValues()
End If
End Sub
Protected Function ConnectToDB(query As String) As SqlDataReader
Dim strConn As String = GlobalVariables.DataSource
'variables
Dim connnection As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim result As SqlDataReader = Nothing
'
Dim strSQL As String = query
connnection = New SqlConnection(strConn)
cmd = New SqlCommand(strSQL, connnection)
connnection.Open()
result = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return result
End Function
Protected Sub DDLCompany_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim result As SqlDataReader = Nothing
Dim constructs As New List(Of String)()
constructs = LoadConstruct()
Try
'sanitization for Company Name
Dim Company As String = Trim(DDLCompany.SelectedValue)
Dim CompanyName As String = Company
Dim pattern As String = "[']"
Dim replacement As String = ""
Dim reg As New Regex(pattern)
If reg.IsMatch(Company) Then
Dim replaceCompany As String = reg.Replace(Company, pattern, replacement)
CompanyName = replaceCompany
End If
If DDLCompany.SelectedValue IsNot "" Then
For Each construct As [String] In constructs
query = "SELECT * FROM IncomeStatement WHERE Company = @CompanyName AND FinancialConstruct = @Construct"
result = ConnectToDB(query)
If result.Read() Then
'does not work after updating columns in IncomeStatement table
'unsure what is causing data not to display
Dim value1 As String = If(result.Item("Y2020") = 0, "-", result.Item("Y2020"))
Dim value2 As String = If(result.Item("Y2021") = 0, "-", result.Item("Y2021"))
Dim value3 As String = If(result.Item("Y2022") = 0, "-", result.Item("Y2022"))
Dim value4 As String = If(result.Item("Y2023") = 0, "-", result.Item("Y2023"))
'works
'Dim value1 As String = If(result.Item("Y2012") = 0, "-", result.Item("Y2012"))
'Dim value2 As String = If(result.Item("Y2013") = 0, "-", result.Item("Y2013"))
'Dim value3 As String = If(result.Item("Y2014") = 0, "-", result.Item("Y2014"))
'Dim value4 As String = If(result.Item("Y2015") = 0, "-", result.Item("Y2015"))
SetLabelValues(construct, value1, value2, value3, value4)
End If
Next
Else
LoadNoValues()
End If
Catch ex As Exception
Console.WriteLine(ex)
End Try
End Sub
Private Function LoadConstruct() As List(Of String)
'Return constructs
Dim constructs As New List(Of String)()
query = "Select Distinct FinancialConstruct From IncomeStatement"
Dim result As SqlDataReader = ConnectToDB(query)
For Each row In result
constructs.Add(row("FinancialConstruct"))
Next
Return constructs
End Function
Private Sub SetLabelValues(constructor As String, value1 As String, value2 As String, value3 As String, value4 As String)`
Select Case constructor
Case "Total Revenue"
lblTotalRevenue1.Text = If(value1 = "-", value1, FormatCurrency(value1))
lblTotalRevenue2.Text = If(value2 = "-", value2, FormatCurrency(value2))
lblTotalRevenue3.Text = If(value3 = "-", value3, FormatCurrency(value3))
lblTotalRevenue4.Text = If(value4 = "-", value4, FormatCurrency(value4))
Exit Select
Case "Cost of Revenue"
lblCostofRevenue1.Text = If(value1 = "-", value1, FormatCurrency(value1))
lblCostofRevenue2.Text = If(value2 = "-", value2, FormatCurrency(value2))
lblCostofRevenue3.Text = If(value3 = "-", value3, FormatCurrency(value3))
lblCostofRevenue4.Text = If(value4 = "-", value4, FormatCurrency(value4))
Exit Select
...
Private Sub LoadNoValues()
lblTotalRevenue1.Text = "-"
lblTotalRevenue2.Text = "-"
lblTotalRevenue3.Text = "-"
lblTotalRevenue4.Text = "-"
lblCostofRevenue1.Text = "-"
lblCostofRevenue2.Text = "-"
lblCostofRevenue3.Text = "-"
lblCostofRevenue4.Text = "-"
...
I was expecting the updated columns and updated years to work, but did not. I have tried using Chrome and Firefox with cleared cache. I also cleared the cache in visual studio as well. I was also thinking of refactoring to just have one label per year of each field so it wouldn’t need so many.