How do I use SqlDataReader to add Totals row to the bottom of my table

I am using SqlDataReader to build a table. I want to add a "Total" row at the bottom of the table to sum up all the values in each column. I know how to do this when using the Gridcontrol but for this project I need to use SqlDataReader. I'm in the very early stages of learning C# so my knowlegde of syntax and classes is pretty weak.  This table generation is working now , just the total columns is not added

Here is how I am building the table.

private void BuildTable(SqlDataReader data, Table table)
        { CreateColumns(table);
          CreateRowHeadings(table);
          while (data.Read())
           CreateRow(table, data);
        }

I know how to calculate the totals using the GridControl and display in the "FooterText" . So I'll try and adapt that once I figure out how to add the total row to the bottom.

This is how I am creating the rows and columns

private void CreateRowHeadings( Table table )
{ Row row = table.Rows.Add( 40, Font.TimesBold, 10, RgbColor.Black, RgbColor.LightGrey );
 row.Align = CellAlign.Center;
 row.VAlign = CellVAlign.Top;
 row.Cells.Add( "Day" );
 row.Cells.Add( "Present # " );
 row.Cells.Add( "Present $$" );
 row.Cells.Add( "Return #" );
 row.Cells.Add( "Return $$" );
 row.Cells.Add( "Collect #" );
 row.Cells.Add( "Collect $$" );
 row.Cells.Add( "Total #" );
 row.Cells.Add( "Total $$" );
 row.Cells.Add( "Echo Date" );
 row.Cells.Add( "DFS Date");
}
       
private void CreateRow(Table table, SqlDataReader data )
{
 Row row = table.Rows.Add( 20 );
 row.Cells.Add( data.GetString(0) , Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1 );
 row.Cells.Add( data.GetInt32(1).ToString( ));
 row.Cells.Add( data.GetDecimal(2).ToString( "$0.00" ));
 row.Cells.Add( data.GetInt32(3).ToString( ));
 row.Cells.Add(data.GetDecimal(4).ToString("($0.00)"));
 row.Cells.Add( data.GetInt32(5).ToString( ));
 row.Cells.Add(data.GetDecimal(6).ToString("$0.00"));
 row.Cells.Add( data.GetInt32(7).ToString( ));
 row.Cells.Add(data.GetDecimal(8).ToString("$0.00"));
 row.Cells.Add( data.GetString(9));
 row.Cells.Add( data.GetString(10));
}
Private void CreateColumns( Table table )
{
            table.Columns.Add(65);
            table.Columns.Add(25);
            table.Columns.Add(65);
            table.Columns.Add(25);
            table.Columns.Add(60);
            table.Columns.Add(25);
            table.Columns.Add(60);
            table.Columns.Add(25);
            table.Columns.Add(60);
            table.Columns.Add(60);
            table.Columns.Add(60);
}

-Steve

svasilakosAsked:
Who is Participating?
 
surajgupthaConnect With a Mentor Commented:
Before every
row.Cells.Add(data.GetString(10));
check if it is null
if(data != dbnull.value)
{
row.Cells.Add(data.GetString(10));
}

Do this for all Data.GetXXX
0
 
surajgupthaCommented:
Lets assume u want to sum up the total $

private void BuildTable(SqlDataReader data, Table table)
        {
          Decimal TotalDollar = 0.0;
          CreateColumns(table);
          CreateRowHeadings(table);
          while (data.Read())
{
           totaldollar+=CreateRow(table, data);
}
Grid.Footer = totalDollar.ToString($0.00);
        }

private Decimal CreateRow(Table table, SqlDataReader data )
{
 Row row = table.Rows.Add( 20 );
 row.Cells.Add( data.GetString(0) , Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1 );
 row.Cells.Add( data.GetInt32(1).ToString( ));
 row.Cells.Add( data.GetDecimal(2).ToString( "$0.00" ));
 row.Cells.Add( data.GetInt32(3).ToString( ));
 row.Cells.Add(data.GetDecimal(4).ToString("($0.00)"));
 row.Cells.Add( data.GetInt32(5).ToString( ));
 row.Cells.Add(data.GetDecimal(6).ToString("$0.00"));
 row.Cells.Add( data.GetInt32(7).ToString( ));
 row.Cells.Add(data.GetDecimal(8).ToString("$0.00"));
 row.Cells.Add( data.GetString(9));
 row.Cells.Add( data.GetString(10));

return  (data.GetDecinam(8));
}
0
 
Gautham JanardhanCommented:
using the sqldatareader is a cvery bad idea in this case as u can use the Adapter.Fill() method to directly fill the datatable

still if u want to do it using SQlDAtaReader u can use the Datatable.Compute() function to calculate the total

object obj = DataTable.Compute("SUM(COLUMNNAME","ANY FILTER");

u can repeat  this on all columns u want to get the desired result
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
svasilakosAuthor Commented:
Where do I put the  object obj = DataTable.Compute("SUM(COLUMNNAME","ANY FILTER");

Regarding   surajguptha: , recomendation.
 I'm getting this error in the event log

The name 'Grid' does not exist in the current context.    I can see Grid does not exist. Should I use something else.

Also I assume you  meant

Grid.Footer = totalDollar.ToString("$0.00");
instead of  Grid.Footer = totalDollar.ToString($0.00);

and
{
       CreateRow(table, data);    
       totaldollar += CreateRow(table, data);
 }

instead  of

{
       totaldollar += CreateRow(table, data);
 }

-Steve
Lastly to comment on gauthampj: , thanks I know SqlDataReader is bad...I will move away from it to DataTable()  probably or Adapter.Fill() . I'm just testing a PDF export product from cete software and all their examples use SqlDataReader, and I'm rushing to get this "demo" project out.


0
 
surajgupthaCommented:
What is the name of ur datagrid? I just gave the same Grid, please reply it with ur datagrid name.

Here's another example for adding a footer to the datagrid
http://aspnet.4guysfromrolla.com/articles/020503-1.aspx

> Steve, just reiterating what gautham says, i think it would be better if u used the dataset/ datatable instead. you are just increasing the complexity of your code by using a datareader and then constructing a datatable. The Fill method would generate the datatable you are trying to build with just one line of code.
0
 
svasilakosAuthor Commented:
UnderStood on not using SqlDataReader. I'm trying to crank out a"demo" PDF generator using software called DynamicPDF from a company called cete (www.cete.com ) . I'll convert to DataTable() in a few days. It's just my understanding of c# is weak so I am modifying their examples which use SqlDataReader. I use DataTable with some other stuff I did in the past.

On to your question. This may be stupid but I'm not sure what the name is, they are not really using  a "grid" or atleast I don't think so.

Just to be complete here is my entire code, with your additions.

using System;
using System.Data;
using System.Data.SqlClient;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.IO;
using ceTe.DynamicPDF.Text;
using ceTe.DynamicPDF.PageElements;


public partial class WebApp_CheckDailySettleSumSiteDFSOPS_PDF : System.Web.UI.Page
   {
        protected CHKDailySumRepCriteria repCriteria;    
       
        static string dBConnString =
        System.Configuration.ConfigurationSettings.AppSettings["DFSConnectionString2"];

            protected void Page_Load(object sender, System.EventArgs e)
            {
            repCriteria = (CHKDailySumRepCriteria)Session[SessionKeys.CHKDailySumRepCriteria];      
           
            // Create a document and set it's properties
                  ceTe.DynamicPDF.Document document = new ceTe.DynamicPDF.Document();
            document.Creator = "CheckDailySettleSumSiteDFSOPS_PDF.aspx";
                  document.Author = "Steve Vasilakos";
                  document.Title = "Check Cashing Daily Summary Report";

                  // Establises connection to the database
                  SqlConnection connection = GetOpenDBConn();
                  SqlDataReader data = GetDailySumData( connection );
           
                  
                  //Create a Table and set it's properties
            Table table = new Table(0, 0,512,600, ceTe.DynamicPDF.Font.Helvetica, 10);
            table.BorderColor = Grayscale.Black;
                  table.RepeatColumnHeaderCount = 1;
                  table.RepeatRowHeaderCount = 1;
                  
                  // Builds the report
            BuildTable(data, table);
            int currentRow = 0;
            int currentColumn = 0;
            do
            {
                currentRow++;
                currentColumn = 1;
                AddTableToPage(document, table, currentRow, currentColumn);
                Table overflowTable = table.GetOverflowColumns();
                do
                {
                    currentColumn++;
                    AddTableToPage(document, overflowTable, currentRow, currentColumn);
                    overflowTable = overflowTable.GetOverflowColumns();
                }
                while (overflowTable != null);
                table = table.GetOverflowRows();
            } while (table != null);

            // Cleans up database connections
            data.Close();
            connection.Close();
                  
                  // Outputs the SimpleReport to the current web page
                  document.DrawToWeb( "ChkDailySumbySettleDate.pdf" );
            //Visible = false;
            }

            private void AddTableToPage( Document document, Table table, int currentRow, int currentColumn )
            {
            Page page = new Page(PageSize.Letter, PageOrientation.Landscape);
                  if( table != null )
                        page.Elements.Add( table );
            page.Elements.Add(new Label("(" + currentRow + "," + currentColumn + ")", 0, page.Dimensions.Body.Height - 40, page.Dimensions.Body.Width, 40, Font.Helvetica, 12, TextAlign.Center));
            document.Pages.Add( page );

           
            }

        private void BuildTable(SqlDataReader data, Table table) //SqlDataReader data, Table table )
        {
          double totaldollar = 0.0;
          CreateColumns(table);
          CreateRowHeadings(table);
          while (data.Read())
         {
           CreateRow(table, data);    
           totaldollar += CreateRow(table, data);
         }
         Grid.Footer = totalDollar.ToString("$0.00");
        }
       
       
        //{

        //CreateColumns(table);
        //CreateRowHeadings(table);
        //while (data.Read())
          //  CreateRow(table, data);
       // }

            private void CreateRowHeadings( Table table )
            {
                  Row row = table.Rows.Add( 40, Font.TimesBold, 10, RgbColor.Black, RgbColor.LightGrey );
                  row.Align = CellAlign.Center;
                  row.VAlign = CellVAlign.Top;
                  row.Cells.Add( "Day" );
                  row.Cells.Add( "Present # " );
                  row.Cells.Add( "Present $$" );
                  row.Cells.Add( "Return #" );
                  row.Cells.Add( "Return $$" );
                  row.Cells.Add( "Collect #" );
                  row.Cells.Add( "Collect $$" );
                  row.Cells.Add( "Total #" );
                  row.Cells.Add( "Total $$" );
                  row.Cells.Add( "Echo Date" );
            row.Cells.Add( "DFS Date");
            }
       
        private double CreateRow(Table table, SqlDataReader data )
            {
           

            Row row = table.Rows.Add( 20 );
                  row.Cells.Add( data.GetString(0) , Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1 );
                  row.Cells.Add( data.GetInt32(1).ToString( ));
            row.Cells.Add( data.GetDecimal(2).ToString( "$0.00" ));
            row.Cells.Add( data.GetInt32(3).ToString( ));
            row.Cells.Add(data.GetDecimal(4).ToString("($0.00)"));
            row.Cells.Add( data.GetInt32(5).ToString( ));
            row.Cells.Add(data.GetDecimal(6).ToString("$0.00"));
            row.Cells.Add( data.GetInt32(7).ToString( ));
            row.Cells.Add(data.GetDecimal(8).ToString("$0.00"));
            row.Cells.Add( data.GetString(9));
            row.Cells.Add( data.GetString(10));

            return  (data.GetDouble(8));

                                    
            }

            private void CreateColumns( Table table )
            {
            table.Columns.Add(65);
            table.Columns.Add(25);
            table.Columns.Add(65);
            table.Columns.Add(25);
            table.Columns.Add(60);
            table.Columns.Add(25);
            table.Columns.Add(60);
            table.Columns.Add(25);
            table.Columns.Add(60);
            table.Columns.Add(60);
            table.Columns.Add(60);
            }

        private SqlConnection GetOpenDBConn()
            {
                  // Creates and opens a database connection
            SqlConnection connection = new SqlConnection( dBConnString );
           
                  connection.Open();
                  return connection;
            }

       private SqlDataReader GetDailySumData(SqlConnection connection)
            {
                  
            DateTime from = this.repCriteria.fromDate;
            DateTime to = this.repCriteria.toDate;
            int siteId = this.repCriteria.siteId;
            int typeId = this.repCriteria.typeId;

                                   
            SqlCommand storedProcCommand = new SqlCommand("sp_REPORT_CheckDailySumBySettleDate_DFSOPS", connection);
            storedProcCommand.CommandType = CommandType.StoredProcedure;
            storedProcCommand.Parameters.Add("@sinceWhen", from);
            storedProcCommand.Parameters.Add("@untilWhen", to);
            storedProcCommand.Parameters.Add("@siteid", siteId);
            storedProcCommand.Parameters.Add("@transtype", typeId);

                  SqlDataReader dataReader = storedProcCommand.ExecuteReader();
                  return dataReader;
            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
            }
            #endregion
      }



0
 
svasilakosAuthor Commented:
One other thing, the aspx page is  just this that's it, the cs file does all the work

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckDailySettleSumSiteDFSOPS_PDF.aspx.cs" Inherits="WebApp_CheckDailySettleSumSiteDFSOPS_PDF" %>
-steve
0
 
surajgupthaCommented:
Call CreateFooter passing the totaldollar after other rows have been added

private Void CreateFooter(Table table, Decimal total)
{
 Row row = table.Rows.Add( 20 );
 row.Cells.Add( data.GetString(0) , Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1 );
 row.Cells.Add( "");
 row.Cells.Add( "");
 row.Cells.Add( "");
 row.Cells.Add( "");
 row.Cells.Add( "");
 row.Cells.Add( "");
 row.Cells.Add(total.ToString());
}
0
 
svasilakosAuthor Commented:
OK. I think I'm almost there.  I do not get any errors but I know I'm putting this in the wrong place and not calling it.  Last bit help

Here is what I have now.  Also I had to add SqlDataReader to your CreateFooter() becuase data was not defined.

 private void BuildTable(SqlDataReader data, Table table) //SqlDataReader data, Table table )
        {
          double totaldollar = 0.0;
          CreateColumns(table);
          CreateRowHeadings(table);
          while (data.Read())
         {
         
           CreateRow(table, data);
           CreateFooter(table, data);    
           totaldollar += CreateRow(table, data);
         }
         
        }
       
       
            private void CreateRowHeadings( Table table )
            {
                  Row row = table.Rows.Add( 40, Font.TimesBold, 10, RgbColor.Black, RgbColor.LightGrey );
                  row.Align = CellAlign.Center;
                  row.VAlign = CellVAlign.Top;
                  row.Cells.Add( "Day" );
                  row.Cells.Add( "Present # " );
                  row.Cells.Add( "Present $$" );
                  row.Cells.Add( "Return #" );
                  row.Cells.Add( "Return $$" );
                  row.Cells.Add( "Collect #" );
                  row.Cells.Add( "Collect $$" );
                  row.Cells.Add( "Total #" );
                  row.Cells.Add( "Total $$" );
                  row.Cells.Add( "Echo Date" );
            row.Cells.Add( "DFS Date");
            }
       
       
         private void CreateRow(Table table, SqlDataReader data )
             {
            Row row = table.Rows.Add( 20 );
            row.Cells.Add( data.GetString(0) , Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1 );
            row.Cells.Add( data.GetInt32(1).ToString( ));
            row.Cells.Add( data.GetDecimal(2).ToString( "$0.00" ));
            row.Cells.Add( data.GetInt32(3).ToString( ));
            row.Cells.Add(data.GetDecimal(4).ToString("($0.00)"));
            row.Cells.Add( data.GetInt32(5).ToString( ));
            row.Cells.Add(data.GetDecimal(6).ToString("$0.00"));
            row.Cells.Add( data.GetInt32(7).ToString( ));
            row.Cells.Add(data.GetDecimal(8).ToString("$0.00"));
            row.Cells.Add( data.GetString(9));
            row.Cells.Add( data.GetString(10));

            return  (data.GetDouble(8));

                                    
             }

    private void CreateFooter(Table table, SqlDataReader data, Decimal total)
    {
        Row row = table.Rows.Add(20);
        row.Cells.Add(data.GetString(0), Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1);
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add(total.ToString());
    }
0
 
surajgupthaCommented:
private void BuildTable(SqlDataReader data, Table table) //SqlDataReader data, Table table )
        {
          double totaldollar = 0.0;
          CreateColumns(table);
          CreateRowHeadings(table);
          while (data.Read())
         {
         
           CreateRow(table, data);
           totaldollar += CreateRow(table, data);
         }
           CreateFooter(table, totaldollar );            
        }
       
0
 
svasilakosAuthor Commented:
Almost done..

If I use double I get an exception

\WebApp\CheckDailySettleSumSiteDFSOPS_PDF.aspx.cs(88): error CS0019: Operator '+=' cannot be applied to operands of type 'double' and 'void'

if I use decimal I get
    Exception message: c:\Inetpub\wwwroot\g8Ph2\WebApp\CheckDailySettleSumSiteDFSOPS_PDF.aspx.cs(81): error CS0664: Literal of type double cannot be implicitly converted to type 'decimal'; use an 'M' suffix to create a literal of this type

Also do I still need

return  (data.GetDecimal(8));     Under the CreateRow method

-Steve




0
 
surajgupthaCommented:
Change this signature    private void CreateRow(Table table, SqlDataReader data )  to
private double CreateRow(Table table, SqlDataReader data )
0
 
svasilakosAuthor Commented:
error CS1501: No overload for method 'CreateFooter' takes '2' arguments. I know that's an easy one..

Here is the code:

private void BuildTable(SqlDataReader data, Table table)
         {
          double totaldollar = 0.0;
          CreateColumns(table);
          CreateRowHeadings(table);
          while (data.Read())
         {
         
           CreateRow(table, data);
           totaldollar += CreateRow(table, data);
   
         }
           CreateFooter(table, totaldollar );            
        }

private void CreateFooter(Table table, SqlDataReader data, decimal total)
    {
        Row row = table.Rows.Add(20);
        row.Cells.Add(data.GetString(0), Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1);
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add(total.ToString("$0.00"));
    }
0
 
surajgupthaCommented:
Change CreateFooter(table, totaldollar );  
To
CreateFooter(table, data, totaldollar );  
0
 
svasilakosAuthor Commented:
Very sorry to keep hammering you.....

Getting this error:
(92): error CS1502: The best overloaded method match for 'WebApp_CheckDailySettleSumSiteDFSOPS_PDF.CreateFooter(ceTe.DynamicPDF.PageElements.Table, System.Data.SqlClient.SqlDataReader, decimal)' has some invalid arguments


Code:
private void BuildTable(SqlDataReader data, Table table)
         {
          double totaldollar = 0.0;
          CreateColumns(table);
          CreateRowHeadings(table);
          while (data.Read())
         {
         
           CreateRow(table, data);
           totaldollar += CreateRow(table, data);
   
         }
           CreateFooter(table, data, totaldollar );            
        }
0
 
surajgupthaCommented:
private void CreateFooter(Table table, SqlDataReader data, double total)
    {
        Row row = table.Rows.Add(20);
        row.Cells.Add(data.GetString(0), Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1);
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add(total.ToString("$0.00"));
    }

0
 
svasilakosAuthor Commented:
(130): error CS0266: Cannot implicitly convert type 'decimal' to 'double'. An explicit conversion exists (are you missing a cast?)

Here is line 130:

private double CreateRow(Table table, SqlDataReader data)
    {
        Row row = table.Rows.Add(20);
        row.Cells.Add(data.GetString(0), Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1);
        row.Cells.Add(data.GetInt32(1).ToString());
        row.Cells.Add(data.GetDecimal(2).ToString("$0.00"));
        row.Cells.Add(data.GetInt32(3).ToString());
        row.Cells.Add(data.GetDecimal(4).ToString("($0.00)"));
        row.Cells.Add(data.GetInt32(5).ToString());
        row.Cells.Add(data.GetDecimal(6).ToString("$0.00"));
        row.Cells.Add(data.GetInt32(7).ToString());
        row.Cells.Add(data.GetDecimal(8).ToString("$0.00"));
        row.Cells.Add(data.GetString(9));
        row.Cells.Add(data.GetString(10));

        return (data.GetDecimal(8));   //This is line 130


    }


    private void CreateFooter(Table table, SqlDataReader data, double total)
    {
        Row row = table.Rows.Add(20);
        row.Cells.Add(data.GetString(0), Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1);
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add(total.ToString("$0.00"));
    }
0
 
surajgupthaCommented:
I have changed all of them to Decimal. No Double's anymore.

private Decimal CreateRow(Table table, SqlDataReader data)
    {
        Row row = table.Rows.Add(20);
        row.Cells.Add(data.GetString(0), Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1);
        row.Cells.Add(data.GetInt32(1).ToString());
        row.Cells.Add(data.GetDecimal(2).ToString("$0.00"));
        row.Cells.Add(data.GetInt32(3).ToString());
        row.Cells.Add(data.GetDecimal(4).ToString("($0.00)"));
        row.Cells.Add(data.GetInt32(5).ToString());
        row.Cells.Add(data.GetDecimal(6).ToString("$0.00"));
        row.Cells.Add(data.GetInt32(7).ToString());
        row.Cells.Add(data.GetDecimal(8).ToString("$0.00"));
        row.Cells.Add(data.GetString(9));
        row.Cells.Add(data.GetString(10));

        return (data.GetDecimal(8));   //This is line 130


    }


    private void CreateFooter(Table table, SqlDataReader data, Decimal total)
    {
        Row row = table.Rows.Add(20);
        row.Cells.Add(data.GetString(0), Font.Helvetica, 12, RgbColor.Black, RgbColor.LightGrey, 1);
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add("");
        row.Cells.Add(total.ToString("$0.00"));
    }

private void BuildTable(SqlDataReader data, Table table)
         {
          Decimal totaldollar = 0.0;
          CreateColumns(table);
          CreateRowHeadings(table);
          while (data.Read())
         {
         
           CreateRow(table, data);
           totaldollar += CreateRow(table, data);
   
         }
           CreateFooter(table, data, totaldollar );            
        }
0
 
svasilakosAuthor Commented:
Thanks for your patience....I know what you mean now about not using SqlDataReader

I made those changes, but.. now

Exception information:
    Exception type: HttpCompileException
    Exception message: c:\Inetpub\wwwroot\g8Ph2\WebApp\CheckDailySettleSumSiteDFSOPS_PDF.aspx.cs(82): error CS0664: Literal of type double cannot be implicitly converted to type 'decimal'; use an 'M' suffix to create a literal of this type

I can change the data type in my stored procedure...I'm using smallmoney right now

0
 
surajgupthaCommented:
which line does this error occur in?
Can u change and try?
0
 
svasilakosAuthor Commented:
It occurs in this line, I need to rework the query a bit. It is currency I'm dealing with so I do not want to drop the decimal ( or cents I should say)

private void BuildTable(SqlDataReader data, Table table)
    {
        Decimal totaldollar = 0.0;  // this is line 82
        CreateColumns(table);
        CreateRowHeadings(table);
        while (data.Read())
        {

            CreateRow(table, data);
            totaldollar += CreateRow(table, data);

        }
        CreateFooter(table, data, totaldollar);
    }










0
 
svasilakosAuthor Commented:
I tried changing to Int but same problem...

I'll keep trying











0
 
surajgupthaCommented:
Try Decimal totaldollar = 0.0D; or
Decimal totaldollar = 0.0M;
0
 
svasilakosAuthor Commented:
Strange. Using M got rid of the error but I get

Exception information:
    Exception type: InvalidOperationException
    Exception message: Invalid attempt to read when no data is present.
0
 
svasilakosAuthor Commented:
Do I need to define dbnull?

I'm getting

error CS0103: The name 'dbnull' does not exist in the current context

The other thing is I know all the columns have data: This is how the report looks
Day # Settled $'s Settled # of NSF NSF Amount # Collected Collect Amount Total Settled NET Settled Amount Echo Settle Date DFS Settle Date
09/04/2007 53 $7,180.00  2 ($500.00)  0 $0.00  55 $6,680.00  09/04/2007 09/06/2007
09/05/2007 11 $1,545.00  1 ($50.00)  0 $0.00  12 $1,495.00  09/05/2007 09/07/2007
09/06/2007 13 $1,375.00  0 ($0.00)  0 $0.00  13 $1,375.00  09/06/2007 09/10/2007
09/07/2007 22 $2,565.00  4 ($400.00)  0 $0.00  26 $2,165.00  09/07/2007 09/11/2007
09/10/2007 40 $5,965.00  0 ($0.00)  0 $0.00  40 $5,965.00  09/10/2007 09/12/2007
09/11/2007 15 $2,310.00  2 ($500.00)  0 $0.00  17 $1,810.00  09/11/2007 09/13/2007
09/12/2007 9 $960.00  0 ($0.00)  0 $0.00  9 $960.00  09/12/2007 09/14/2007
09/13/2007 13 $1,450.00  4 ($1,200.00)  0 $0.00  17 $250.00  09/13/2007 09/17/2007

-Steve

0
 
surajgupthaCommented:
DBNull.Value not dbnull.value

Buddy, with all due respects i have a suggestion. My guess is that If you got some training on c# , it would really help increase your productivity.
0
 
svasilakosAuthor Commented:
I fully agree. Enough said. I really appreaciate the nearly entire plus you spent on this....I'll take your suggestion..

Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.