using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
class ProgrammaticDataDisplay : Form
{
public ProgrammaticDataDisplay()
{
InitializeComponent();
string connectionString = "server=localhost;Trusted_Connection=yes; database=northwind";
string commandString = "Select CompanyName, ContactName, ContactTitle, Phone, Fax from Customers";
SqlDataAdapter DataAdapter = new SqlDataAdapter( commandString, connectionString );
DataSet DataSet = new DataSet();
DataAdapter.Fill( DataSet, "Customers" );
dataGridView1.DataSource = DataSet.Tables["Customers"].DefaultView;
}
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
( ( System.ComponentModel.ISupportInitialize ) ( this.dataGridView1 ) ).BeginInit();
this.SuspendLayout();
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point( 0, 0 );
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size( 579, 262 );
this.dataGridView1.TabIndex = 0;
this.AutoScaleBaseSize = new System.Drawing.Size( 5, 13 );
this.ClientSize = new System.Drawing.Size( 579, 262 );
this.Controls.Add( this.dataGridView1 );
this.Name = "ProgrammaticDataDisplay";
this.Text = "Programmatic Data Display";
( ( System.ComponentModel.ISupportInitialize ) ( this.dataGridView1 ) ).EndInit();
this.ResumeLayout( false );
}
private System.Windows.Forms.DataGridView dataGridView1;
[STAThread]
static void Main()
{
Application.Run( new ProgrammaticDataDisplay() );
}
}
|