You are on page 1of 21

Unit 5

Data Binding and Deployment


Data Binding
• Data binding is a process through which we can
bind the GUI controls like Textbox or Listbox with
data source i.e dataset.
• The data from dataset can be directly displayed
in the controls
• The control is perfectly mapped with the data
source
• So changes made in control reflect in data source
and vice versa.
Types:
Simple Data binding:

• In this type of binding controls like textbox and


labels are binded with specific values of data
field
• Controls used in this binding can display single
value at a time.
• Eg: salary of emp having specific id can be shown
by simple data binding
• TextBox1.DataBindings.Add("text",
myds.Tables(0), "ID")
Complex Data binding:

• In this type of binding controls like


listbox,combobox are binded with multiple
values.
• Controls used in this data binding can display a
multiple values at a time
• Eg: emp_id of all the emp can be shown by
complex data
ListBox1.DataSource = myds.Tables(0)
ListBox1.DisplayMember = "ID"
Simple Data binding
Imports System.Data.OleDb
Imports System.Data

Public Class Form1


Private conn As OleDbConnection
Private adpt As OleDbDataAdapter
Private cmd As OleDbCommandBuilder
Private myds As DataSet
Private sqlstr As String

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Apurva\Documents\Student.accdb")
conn.Open()
myds = New DataSet
sqlstr = "select * from info"
adpt = New OleDbDataAdapter(sqlstr, conn)
adpt.SelectCommand.CommandText = sqlstr
cmd = New OleDbCommandBuilder(adpt)
adpt.Fill(myds, "info")
TextBox1.DataBindings.Add("text", myds.Tables(0), "ID")
TextBox2.DataBindings.Add("text", myds.Tables(0), "name")

End Sub
End Class
Output
Complex Data binding
Imports System.Data.OleDb
Imports System.Data

Public Class Form1


Private conn As OleDbConnection
Private adpt As OleDbDataAdapter
Private cmd As OleDbCommandBuilder
Dim myds As DataSet
Dim sqlstr As String

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Apurva\Documents\Student.accdb")
conn.Open()
myds = New DataSet
sqlstr = "select * from info"
adpt = New OleDbDataAdapter(sqlstr, conn)
adpt.SelectCommand.CommandText = sqlstr
cmd = New OleDbCommandBuilder(adpt)
adpt.Fill(myds, "info")
ListBox1.DataSource = myds.Tables(0)
ListBox1.DisplayMember = "ID"
ComboBox1.DataSource = myds.Tables(0)
ComboBox1.DisplayMember = "name"
End Sub
End Class
Output
Deployment
• Open the project u want to create setup
• Go to-> Extensions -> Manage extension
• Select Microsoft visual studio installer project
• Download this extension.
Click download
• This extension will get downloaded and u have
to close the project.
• Automatically a setup will run after closing ur
project
• Click modify->end task ->close

• Now open ur project bulid the project


• Right Click on Solution in Solution Explorer-
>ADD->New Project
Click Setup project
Double click Application folder
Right click ->Add->Project Output
Select primary output ->ok
Right click Add->Primary output
Right click->Add->file->icon(.ico)
• In ‘User Desktop’ ->right click->create shortcut->Application
program-> primary output
• Add icons if u require(click properties ->icons-> select icon
which has .ico extention)
• Repeat same process for ‘Users Program Menu’

• Now build the project again


• Close the project
• Go to C:\Users\-----\source\repos
• Double click ur project name
• U will get a setup folder double click it->debug->
• Run the setup file
• Next->next-> ok

You might also like