-
May 26th, 2009, 02:18 PM
#1
Barcode Data Binding in Windows Forms
Technologies used
- Neodynamic Barcode Professional for Windows Forms (any version)
- Microsoft .NET Framework 1.0 or greater
- Microsoft Visual Studio .NET 2002 or 2003
- Microsoft Visual Studio 2005
- Microsoft Visual Studio 2005 Express Editions (VB, C#, J#, and C++)
In the following step by step guide we're going to create a simple Windows Forms application that accomplishes data binding tasks. In this sample we use Microsoft's Northwind database sample for SQL Server.
Follow these steps:
1- Ensure you have installed Barcode Professional for Windows Forms
2- Launch Visual Studio and create a new Windows Forms application
3- Open the default Form at design-time and add the following controls as is shown in the following figure:
http://www.neodynamic.com/Support/FA...ure01Small.jpg
4- Now, go to the form class and add the following code:
4.1- Declare this two members variables
Visual Basic .NET
Dim ds As DataSet
Dim bmbProducts As BindingManagerBase
Visual C# .NET
DataSet ds;
BindingManagerBase bmbProducts;
4.2- Add the following code in the Form_Load event procedure VB.NET
Visual Basic .NET
Dim cnn As New System.Data.SqlClient.SqlConnection("server=(local);database=Northwind;integrated security=true")
Dim sqlcmd As New System.Data.SqlClient.SqlCommand("SELECT Products.ProductName, Categories.CategoryName, Products.UnitPrice, Products.ProductID FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID", cnn)
Dim da As New System.Data.SqlClient.SqlDataAdapter(sqlcmd)
ds = New DataSet
da.Fill(ds, "Products")
bmbProducts = BindingContext(ds, "Products")
TextBox1.DataBindings.Add("Text", ds, "Products.ProductName")
TextBox2.DataBindings.Add("Text", ds, "Products.CategoryName")
TextBox3.DataBindings.Add("Text", ds, "Products.UnitPrice")
BarcodeProfessional1.DataBindings.Add("Code", ds, "Products.ProductID")
BarcodeProfessional1.Text = ""
BarcodeProfessional1.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Industrial2of5
Visual C# .NET
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("server=(local);database=Northwind;integrated security=true");
System.Data.SqlClient.SqlCommand sqlcmd = new System.Data.SqlClient.SqlCommand("SELECT Products.ProductName, Categories.CategoryName, Products.UnitPrice, Products.ProductID FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID", cnn);
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(sqlcmd);
ds = new DataSet();
da.Fill(ds, "Products");
bmbProducts = BindingContext[ds, "Products"];
TextBox1.DataBindings.Add("Text", ds, "Products.ProductName");
TextBox2.DataBindings.Add("Text", ds, "Products.CategoryName");
TextBox3.DataBindings.Add("Text", ds, "Products.UnitPrice");
BarcodeProfessional1.DataBindings.Add("Code", ds, "Products.ProductID");
BarcodeProfessional1.Text = "";
BarcodeProfessional1.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Industrial2of5;
4.3- Add the following code in the Click event procedure for << Previous button
Visual Basic .NET
bmbProducts.Position -= 1
Visual C# .NET
bmbProducts.Position -= 1;
4.4- Add the following code in the Click event procedure for Next >> button
Visual Basic .NET
bmbProducts.Position += 1
Visual C# .NET
bmbProducts.Position += 1;
5- That's it. Run the app. You'll get something like the following:
http://www.neodynamic.com/Support/FAQs/33/figure02.jpg
Links:
This Demo
More Demos
Download Barcode Professional for Windows Forms
More Information about Neodynamic Barcode Professional for Windows Forms
Neodynamic
.NET Components & Controls
http://www.neodynamic.com
http://www.barcode-for-net.com
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|