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?
thanks
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