DataView Binding to TextBox : Data Bind TextBox « Database ADO.net « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Database ADO.net » Data Bind TextBoxScreenshots 
DataView Binding to TextBox


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.TextBox textBox1;
      private System.Windows.Forms.TextBox textBox2;
      private System.Data.DataSet dataSet1;
 
      private System.ComponentModel.Container components = null;

      public Form1() {
         InitializeComponent();
      }
      private void InitializeComponent() {
         this.textBox1 = new System.Windows.Forms.TextBox();
         this.textBox2 = new System.Windows.Forms.TextBox();
         this.dataSet1 = new System.Data.DataSet();
         ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
         this.SuspendLayout();
 
         this.textBox1.Location = new System.Drawing.Point(160);
         this.textBox1.Name = "textBox1";
         this.textBox1.TabIndex = 0;
         this.textBox1.Text = "textBox1";
 
         this.textBox2.Location = new System.Drawing.Point(1624);
         this.textBox2.Name = "textBox2";
         this.textBox2.TabIndex = 1;
         this.textBox2.Text = "textBox2";
 
         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(12845);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {this.textBox2,this.textBox1});
         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");

         DataTable myTable = dataSet1.Tables["Employee"];
         DataView dv = new DataView(myTable, "FirstName='Z'","FirstName", DataViewRowState.CurrentRows);

         textBox1.DataBindings.Add("Text", dv, "FirstName");
         textBox2.DataBindings.Add("Text", dv, "LastName");
      }
   }


           
       
Related examples in the same category
1.Bind DataSet to TextBox
2.Simple DataBinding to TextBox
3.Bind String array to a TextBox
4.Bind Database table column to TextBox
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.