I do not know if this is possible but having struggled with this for 3 days now without success, I wanted to try my luck here.
The code below displays the last inserted record from the database and it works fine.
<asp:GridView ID="grv" runat="server" HorizontalAlign="Center" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="WaterAccountNo" HeaderText="Water Acct #" />
<asp:BoundField DataField="ApplicationNo" HeaderText="App #" />
<asp:BoundField DataField="Applicant" HeaderText="Applicant(s)" />
<asp:BoundField DataField="InstallAddress" HeaderText="Address" />
<asp:TemplateField HeaderText="Total Rebate">
<ItemTemplate>
<asp:Label ID="litTotal" runat="server" Text='<%# Convert.ToDouble(Eval("total_Amount")) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="AliceBlue" ForeColor="Black" />
<RowStyle BackColor="#969696" ForeColor="White" />
<HeaderStyle BackColor="Black" ForeColor="GhostWhite" />
</asp:GridView>
<asp:Label ID="lblMsg" />
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim dt As DataTable = New DataTable()
Dim con As New SqlConnection(conString)
Dim sqlStatement As String = "select app.WaterAccountNo,app.ApplicationNo,app.Applicant,ad.InstallAddress + ' ' + ad.InstallCity + ' ' + ad.InstallState + ' ' + ad.InstallZip installAddress,sum(app.Amount) over (order by ad.InstallAddress rows unbounded preceding) as total_Amount, app.DateReceived FROM Applications app inner join Addresses ad on app.InstallAddress=ad.AUTOID inner join Owner o on app.OwnerCode = o.OwnerID inner join ToiletGPF tg on app.ToiletGPFID=tg.ToiletGPFID where app.Batch_No=@bNo and app.ApplicationNo=@appNo group by app.WaterAccountNo,app.ApplicationNo,app.Applicant,ad.InstallAddress, ad.InstallCity,ad.InstallState, ad.InstallZip,app.RebateAmount, app.DateReceived"
Dim sqlCmd As SqlCommand = New SqlCommand(sqlStatement, myConnection)
sqlCmd.Parameters.AddWithValue("@bNo", bNo)
sqlCmd.Parameters.AddWithValue("@appNo", appNo)
Dim sqlDa As SqlDataAdapter = New SqlDataAdapter(sqlCmd)
sqlDa.Fill(dt)
If dt.Rows.Count < 1 Then
lblMsg.Text="Currently, no records"
End If
grv.DataSource = dt
grv.DataBind()
End Sub
The issue is that sometimes, two rows or 3 (3 is the max rows to be inserted) are inserted into the database.
These rows have the same water account number, same address but different application numbers, each application number associated with each dynamically generated row.
Our requirement is to display the amount grand total for records of the same water account number or address.
When I tried using water account number, no record is found.
When I attempt to use address, it last row which is good but does not display the grand total associated with that address.
Can you guys help if this is possible?