Programmatic Data Display : DataGrid « ADO.Net « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » ADO.Net » DataGrid 
32.52.7.Programmatic Data Display
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 SqlDataAdaptercommandString, connectionString );
         DataSet DataSet = new DataSet();
         DataAdapter.FillDataSet, "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.Point0);
         this.dataGridView1.Name = "dataGridView1";
         this.dataGridView1.Size = new System.Drawing.Size579262 );
         this.dataGridView1.TabIndex = 0;
         this.AutoScaleBaseSize = new System.Drawing.Size513 );
         this.ClientSize = new System.Drawing.Size579262 );
         this.Controls.Addthis.dataGridView1 );
         this.Name = "ProgrammaticDataDisplay";
         this.Text = "Programmatic Data Display";
         ( ( System.ComponentModel.ISupportInitialize ) ( this.dataGridView1 ) ).EndInit();
         this.ResumeLayoutfalse );

      }


      private System.Windows.Forms.DataGridView dataGridView1;

      [STAThread]
      static void Main()
      {
         Application.Runnew ProgrammaticDataDisplay() );
      }
   }
32.52.DataGrid
32.52.1.Load data in DataTable to DataGridLoad data in DataTable to DataGrid
32.52.2.Link two DataTable in a DataGridLink two DataTable in a DataGrid
32.52.3.Load Data to DataGridLoad Data to DataGrid
32.52.4.DataGrid View: on data error
32.52.5.Data binding for Multiple Controls
32.52.6.Binding DataSet to DataGrid
32.52.7.Programmatic Data Display
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.