Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » help with c# code

help with c# code

  #1 (permalink)  
New Member
Join Date: Sep 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
help with c# code

hi friends
I want to list all tables in sql server compact 3.5 database and total of a specific column (I have a column name "total" in all tables).when i run the code I get no error but it does not work.
can some tell me what is wrong with the code. I appreciate any help
 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlServerCe;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _35c
    public partial class Form1 : Form
        public Form1()


        private void button2_Click(object sender, EventArgs e)
         private static int getTotal(string connectionString)
            int total = 0;

            using (var connection = new SqlCeConnection("Data Source=|DataDirectory|Northwind.sdf;Password=***"))
                var command = new SqlCeCommand("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'Total';"
                    , connection);

                foreach (var table in from IDataRecord row in command.ExecuteReader()
                                      select new { name = row.GetValue(row.GetOrdinal("TABLE_NAME")) }
                    command.CommandText = String.Format("SELECT SUM(Total) AS Total FROM {0}",;
                    var tableTotal = command.ExecuteScalar();
                    total = total + (tableTotal == DBNull.Value ? 0 : (int)command.ExecuteScalar());
            return total;


Reply With Quote


specific column totals, sql query, tables names

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Match code in link with code with one in file and extract line peuplarchie PHP 3 10-24-09 01:23 AM
Freeze columns in a table Rita Negi Script Requests 1 09-01-09 08:23 AM
OTO Redirect Code Placement Tony S. HTML/XHTML/XML 7 07-25-09 09:31 AM
Need captcha for html+php contact form sujata_ghosh PHP 6 03-22-09 03:46 PM
Explanation of Code... Please davidk19380 Perl 1 02-26-06 01:50 PM

All times are GMT -5. The time now is 08:10 PM.
vBulletin® Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.