Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query output in datagridview

Status
Not open for further replies.

rony01

MIS
Sep 12, 2012
8
US
I am new to c# .I am having trouble to add a datagridview in the below code. can someone tell me how to do it?

Code:
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()
        {
            InitializeComponent();

        }


        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=**"))
            {
                connection.Open();
             
                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}", table.name);  
                    var tableTotal = command.ExecuteScalar();
                    total = total + (tableTotal == DBNull.Value ? 0 : (int)command.ExecuteScalar()); 
                }
                connection.Close();
            }
            return total;

        }


    }
}

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top