Bind DataSet to Label : Data Bind Label « Database ADO.net « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Database ADO.net » Data Bind LabelScreenshots 
Bind DataSet to Label

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

   public class Form1 : System.Windows.Forms.Form {
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.Label label2;
      private System.Data.DataSet dataSet1;
 
      private System.ComponentModel.Container components = null;

      public Form1(){ 
 
         InitializeComponent();
      }

      private void InitializeComponent() {
         this.label1 = new System.Windows.Forms.Label();
         this.label2 = new System.Windows.Forms.Label();
         this.dataSet1 = new System.Data.DataSet();
         ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
         this.SuspendLayout();
 
         this.label1.Location = new System.Drawing.Point(168);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(7216);
         this.label1.TabIndex = 0;
         this.label1.Text = "label1";
 
         this.label2.Location = new System.Drawing.Point(1640);
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size(7216);
         this.label2.TabIndex = 1;
         this.label2.Text = "label2";
 
         this.dataSet1.DataSetName = "NewDataSet";
         this.dataSet1.Locale = new System.Globalization.CultureInfo("en-GB");
 
         this.AutoScaleBaseSize = new System.Drawing.Size(513);
         this.ClientSize = new System.Drawing.Size(12869);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.label2,
                                                                      this.label1});
         this.Name = "Form1";
         this.Text = "Form1";
         this.Load += new System.EventHandler(this.Form1_Load);
         ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
         this.ResumeLayout(false);

      }
 
      static void Main() {
         Application.Run(new Form1());
      }

      private void Form1_Load(object sender, System.EventArgs e) {
         string connString = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";
    
         string SQL = @"select * from employee";

         SqlConnection Conn = new SqlConnection(connString);
         SqlDataAdapter da = new SqlDataAdapter(SQL, Conn);

         da.Fill(dataSet1, "employee");

         // Bind the Label's Text property to the ProductID of the Products table
         label1.DataBindings.Add("Text", dataSet1, "employee.ID");
         // Bind the second label's Text property to the UnitPrice column
         label2.DataBindings.Add("Text", dataSet1, "employee.firstname");
      }
   }



           
       
Related examples in the same category
w_w___w__.j__a__v___a___2__s_.c__om | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.