VPT Lab Anchit

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 42

Visual Programming

Techniques
Introduction to .NET
.NET is a set of common services which can be used on a number
of common languages. These services are executed in the form of
executable code i.e. independent of underlying architecture.

Source
Code

Executable
Code

MSIL

JIT
Compiler

Executio
n

Architecture of VB.NET
.NET framework is Multilanguage environment for
building and running web services, web applications and
windows application. .Net technology aims in providing a
platform for building internet based application in a
faster, efficient and much more reliable manner.

Features Of .NET
2 (Amit Rajput 06/CS/007)
1) .NET is Multilanguage : With .NET platform we can
use several languages. Ex- Vb, C#, J# ,Jsp etc. All these
languages are compiled through an intermediate binary
code which is independent of hard-ware , operating
system and underlying architecture.

2) Common Language Runtime (CLR) : CLR is the


execution engine for .NET framework application. CLR is
responsible for managing memory allocation, starting and
killing threads. It also enforce security policies.

3) Unified programming classes : .NET framework


provides unified, object oriented and extensible set of
class libraries. Across all languages. .NET framework
enables cross language inheritance, error handling and
debugging.

4) Garbage Collection : .There is no need to explicitly


allocate and deallocate memory in .NET.

5) Type Safety: .NET is type safe in the sense that there


is no implicit conversion of data types. The programmer
has to do their own type conversions.

3 (Amit Rajput 06/CS/007)


PROGRAM-1
AIM - Write a program in vb.net to implement a calculator.

Program - Public Class Form1

Dim A As Double

Dim B As Char

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

TB1.Text = "0"

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

TB1.Text = TB1.Text & Button1.Text

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click

TB1.Text = TB1.Text & Button2.Text

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click

TB1.Text = TB1.Text & Button3.Text

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click

TB1.Text = TB1.Text & Button4.Text

4 (Amit Rajput 06/CS/007)


End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click

TB1.Text = TB1.Text & Button5.Text

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button6.Click

TB1.Text = TB1.Text & Button6.Text

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button7.Click

TB1.Text = TB1.Text & Button7.Text

End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button8.Click

TB1.Text = TB1.Text & Button8.Text

End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button9.Click

TB1.Text = TB1.Text & Button9.Text

End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button11.Click

TB1.Text = TB1.Text & Button11.Text

End Sub

5 (Amit Rajput 06/CS/007)


Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click

TB1.Text = TB1.Text & Button10.Text

End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button12.Click

Dim l As Integer

l = TB1.Text.Length

If l = 0 Then

Else

If (TB1.Text.Chars(l - 1) = ".") Then

TB1.Text = TB1.Text.Remove(l - 1, 1)

TB1.Text = TB1.Text & Button12.Text

Else

TB1.Text = TB1.Text & Button12.Text

End If

End If

End Sub

Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button22.Click

TB1.Text = ""

TB1.Focus()

6 (Amit Rajput 06/CS/007)


End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button13.Click

A = TB1.Text

TB1.Clear()

B = "+"

TB1.Focus()

End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button14.Click

A = TB1.Text

TB1.Clear()

B = "-"

TB1.Focus()

End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button15.Click

A = TB1.Text

TB1.Clear()

B = "*"

TB1.Focus()

End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button16.Click

7 (Amit Rajput 06/CS/007)


A = TB1.Text

TB1.Clear()

B = "/"

TB1.Focus()

End Sub

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button17.Click

TB1.Text = Math.Sqrt(TB1.Text)

End Sub

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button18.Click

Dim l As Integer

l = TB1.Text.Length

TB1.Text = TB1.Text.Remove(l - 1, 1)

End Sub

Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button21.Click

A = TB1.Text

TB1.Clear()

B = "P"

TB1.Focus()

End Sub

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button19.Click

8 (Amit Rajput 06/CS/007)


A = TB1.Text

TB1.Clear()

B = "%"

TB1.Focus()

End Sub

Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button20.Click

If B = "+" Then

TB1.Text = A + Val(TB1.Text)

ElseIf B = "-" Then

TB1.Text = A - Val(TB1.Text)

ElseIf B = "*" Then

TB1.Text = A * Val(TB1.Text)

ElseIf B = "/" Then

TB1.Text = A / Val(TB1.Text)

ElseIf B = "P" Then

Dim C As Double

C = TB1.Text

TB1.Text = Math.Pow(A, C)

ElseIf B = "%" Then

TB1.Text = (A * Val(TB1.Text)) / 100

End If

End Sub

End Class

9 (Amit Rajput 06/CS/007)


OUTPUT:- CALCULATOR

10 (Amit Rajput 06/CS/007)


PROGRAM-2
AIM - Write a program for exception handling in vb.net.

Program - Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click

Dim a As Integer

Dim b As Integer

Dim c As Integer

Try

a = TextBox1.Text

b = TextBox2.Text

c = a + b = TextBox3.Text

Catch ex As InvalidCastException

MsgBox(ex.Message)

End Try

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

Dim a As Integer

Dim b As Integer

Dim c As Integer

Try

a = TextBox1.Text

b = TextBox2.Text

c = a \ b

11 (Amit Rajput 06/CS/007)


Catch ex As DivideByZeroException

MsgBox(ex.Message)

End Try

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click

Dim a As Integer

Dim b As Integer

Dim c As Integer

Try

a = TextBox1.Text

b = TextBox2.Text

c = a + b

TextBox3.Text = c

Catch ex As OverflowException

MsgBox(ex.Message)

End Try

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click

Dim a(2) As Integer

Try

a(0) = 1

a(1) = 2

a(2) = 3

a(4) = a(3) + a(2)

Catch ex As IndexOutOfRangeException

MsgBox(ex.Message)

End Try

12 (Amit Rajput 06/CS/007)


End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click

Dim a As String

Dim b As String

Try

b = a.ToUpper()

Catch ex As NullReferenceException

MsgBox(ex.Message)

End Try

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button6.Click

Dim a As Integer

Dim b As Integer

Dim c As Integer

a = TextBox1.Text

b = TextBox2.Text

On Error GoTo handle

c = a / b

TextBox3.Text = c

handle: MsgBox("divide by zero")

End Sub

End Class

OUTPUT:- EXCEPTION HANDLING


13 (Amit Rajput 06/CS/007)
PROGRAM-3
14 (Amit Rajput 06/CS/007)
AIM - Write a program to implement classes in vb.net.
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

Dim a As New arithmatic

Dim c1 As Integer

c1 = TextBox1.Text

a.evenorodd(c1)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click

Dim c As New arithmatic

Dim a1, b1 As Integer

a1 = TextBox1.Text

b1 = textbox2.text

c.swap(a1, b1)

MsgBox(a1 & " " & b1)

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click

Dim b As New arithmatic

Dim a1 As Integer

a1 = TextBox1.Text

b.revofnum(a1)

End Sub

15 (Amit Rajput 06/CS/007)


Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click

Dim b As New arithmatic

Dim a1 As Integer

a1 = TextBox1.Text

b.prime(a1)

End Sub

End Class

Public Class arithmatic

Function evenorodd(ByVal b As Integer) As Integer

Dim rem1 As Integer

rem1 = b Mod 2

If rem1 = 0 Then

MsgBox("even")

Else

MsgBox("odd")

End If

End Function

Function swap(ByRef a As Double, ByRef d As Double) As Double

Dim t As Integer

t = a

a = d

d = t

End Function

Function revofnum(ByVal a As Integer) As Integer

Dim rem1, sum1 As Integer

16 (Amit Rajput 06/CS/007)


While a > 0

rem1 = a Mod 10

sum1 = sum1 * 10 + rem1

a = a / 10

End While

MsgBox(sum1)

End Function

Function prime(ByVal a As Integer) As Integer

Dim i, flag As Integer

For i = 2 To a / 2

If a Mod i = 0 Then

flag = flag + 1

End If

Next

If flag > 0 Then

MsgBox("not prime")

Else

MsgBox("prime")

End If

End Function

End Class

OUTPUT:- IMPLEMENTATION OF CLASSES

17 (Amit Rajput 06/CS/007)


18 (Amit Rajput 06/CS/007)
PROGRAM-4
AIM- Write a program in vb.net to implement user
controls.
Public Class simple

Dim p, r, t As Double

Property mr() As Double

Get

mr = r

End Get

Set(ByVal value As Double)

r = value

End Set

End Property

Property mp() As Double

Get

mp = p

End Get

Set(ByVal value As Double)

p = value

End Set

End Property

Property mt() As Double

Get

mt = t

End Get

Set(ByVal value As Double)

t = value

End Set

19 (Amit Rajput 06/CS/007)


End Property

Function si() As Double

Dim h As Double

h = ((p * r * t) / 100)

Return (h)

End Function

End Class

Public Class UserControl1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

Dim a As New simple

Dim k As Double

a.mp = TextBox1.Text

a.mr = TextBox2.Text

a.mt = TextBox3.Text

k = a.si

MsgBox(k)

End Sub

End Class

20 (Amit Rajput 06/CS/007)


OUTPUT:-USER CONTROL

21 (Amit Rajput 06/CS/007)


PROGRAM-5
AIM - Write a program for using graphics.
Imports System.Drawing

Imports System.Drawing.Drawing2D

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

Dim a, b, c, d As Integer

a = Val(TextBox1.Text)

b = Val(TextBox2.Text)

c = Val(TextBox3.Text)

d = Val(TextBox4.Text)

Dim g As Graphics

g = Me.CreateGraphics

Dim p As New Pen(Color.Red)

g.DrawLine(p, a, b, c, d)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Button2.Click

Dim g As Drawing.Graphics

Dim a, b, c, d As Integer

a = Val(TextBox1.Text)

b = Val(TextBox2.Text)

c = Val(TextBox3.Text)

d = Val(TextBox4.Text)

g = Me.CreateGraphics

22 (Amit Rajput 06/CS/007)


Dim p As New Pen(Color.Red)

g.DrawRectangle(p, a, b, c, d)

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Button3.Click

Dim g As Drawing.Graphics

Dim a, b, c, d As Integer

a = Val(TextBox1.Text)

b = Val(TextBox2.Text)

c = Val(TextBox3.Text)

d = Val(TextBox4.Text)

g = Me.CreateGraphics

Dim p As New Pen(Color.Green)

g.DrawEllipse(p, a, b, c, d)

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Button4.Click

Dim g As Drawing.Graphics

Dim a, b, c, d As Integer

a = Val(TextBox1.Text)

b = Val(TextBox2.Text)

c = Val(TextBox3.Text)

d = Val(TextBox4.Text)

Dim r As Rectangle

g = Me.CreateGraphics

Dim p As New Pen(Color.Blue)

r = New Rectangle(a, b, c, d)

23 (Amit Rajput 06/CS/007)


g.DrawRectangle(p, a, b, c, d)

Dim brush As LinearGradientBrush

brush = New Drawing2D.LinearGradientBrush(r, Color.Pink,


Color.Red, Drawing2D.LinearGradientMode.ForwardDiagonal)

g.FillRectangle(brush, r)

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Button5.Click

Dim g As Drawing.Graphics

Dim a, b, c, d As Integer

a = Val(TextBox1.Text)

b = Val(TextBox2.Text)

c = Val(TextBox3.Text)

d = Val(TextBox4.Text)

Dim r As Rectangle

g = Me.CreateGraphics

Dim p As New Pen(Color.Red)

r = New Rectangle(a, b, c, d)

g.DrawEllipse(p, a, b, c, d)

Dim brush As LinearGradientBrush

brush = New Drawing2D.LinearGradientBrush(r, Color.Pink,


Color.Red, Drawing2D.LinearGradientMode.ForwardDiagonal)

g.FillEllipse(brush, r)

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Button6.Click

Dim g As Drawing.Graphics

Dim a, b, c, d As Integer

24 (Amit Rajput 06/CS/007)


a = Val(TextBox1.Text)

b = Val(TextBox2.Text)

c = Val(TextBox3.Text)

d = Val(TextBox4.Text)

Dim r As Rectangle

g = Me.CreateGraphics

Dim p As New Pen(Color.Red)

r = New Rectangle(a, b, c, d)

Dim brush As HatchBrush

brush = New HatchBrush(HatchStyle.DarkHorizontal, Color.Pink,


Color.Blue)

g.Fillrectangle(brush, r)

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button7.Click

Dim g As Drawing.Graphics

Dim a, b, c, d As Integer

a = Val(TextBox1.Text)

b = Val(TextBox2.Text)

c = Val(TextBox3.Text)

d = Val(TextBox4.Text)

Dim r As Rectangle

g = Me.CreateGraphics

Dim p As New Pen(Color.SeaShell)

r = New Rectangle(a, b, c, d)

g.DrawRectangle(p, a, b, c, d)

p.DashStyle = DashStyle.DashDot

25 (Amit Rajput 06/CS/007)


End Sub

End Class

OUTPUT:-GRAPHICS

Program –6

26 (Amit Rajput 06/CS/007)


AIM-Write a program for Free Hand Drawing
Imports System.Drawing

Imports System.Drawing.Drawing2D

Imports System.Drawing.graphics

Public Class Form1

Dim mousepath As New GraphicsPath

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

If e.Button = Windows.Forms.MouseButtons.Left Then

mousepath.StartFigure()

End If

End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

If e.Button = Windows.Forms.MouseButtons.Left Then

mousepath.AddLine(e.X, e.Y, e.X, e.Y)

End If

PictureBox1.Invalidate()

End Sub

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As


System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

Dim p As New Pen(Color.Red)

e.Graphics.DrawPath(p, mousepath)

End Sub

End Class

OUTPUT:- FREE HAND DRAWING


27 (Amit Rajput 06/CS/007)
Program -7

28 (Amit Rajput 06/CS/007)


AIM- Interoperability
Public Class usercontrol1

Dim starttimer As DateTime

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

If (Timer1.Enabled) Then

Button1.Text = "restart"

Timer1.Stop()

Else

starttimer = DateTime.Now()

Button1.Text = "stop"

Timer1.Start()

End If

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Timer1.Tick

Dim span As New TimeSpan

span = DateTime.Now.Subtract(starttimer)

Label1.Text = span.Minutes.ToString & ":" & span.Seconds.ToString &


":" & span.Milliseconds.ToString

End Sub

End Class

OUTPUT:- INTEROPERABILITY

29 (Amit Rajput 06/CS/007)


Program – 8

30 (Amit Rajput 06/CS/007)


Aim :Design an Application to perform “ADO.NET database connectivity” through database in
VB.NET in connected environment.

Form -1 coding

Imports System.Data.OleDb

Public Class Form1

Dim conn As OleDbConnection

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click

Dim str1 As String

Dim k As String

If RB1.Checked = True Then

k = "married"

Else

k = "unmarried"

End If

Dim comm As New OleDbCommand

str1 = "insert into priya(name,address,phno,status)values('" & TB1.Text & "','" & TB2.Text &
"','" & TB3.Text & "',' " & k & "') "

comm = New OleDbCommand(str1, conn)

comm.ExecuteNonQuery()

MsgBox("data inserted successfully")

TB1.Clear()

TB2.Clear()

TB3.Clear()

31 (Amit Rajput 06/CS/007)


TB1.Focus()

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load

Dim str As String

Dim comm As New OleDbCommand

str = "provider=microsoft.jet.oledb.4.0; data source=C:\Documents and Settings\bsaitm\My


Documents\db6.mdb"

conn = New OleDbConnection(str)

conn.Open()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click

Dim a As New form2

a.show()

Me.Hide()

conn.Close()

End Sub

End Class

Form-2 Coding

Imports system.data.oledb

32 (Amit Rajput 06/CS/007)


Public Class Form2

Dim conn As New OleDbConnection

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

Dim str3 As String

Dim comm As New OleDbCommand

Dim reader As OleDbDataReader

str3 = "select * from priya where name='" & ComboBox1.Text & "'"

comm = New OleDbCommand(str3, conn)

reader = comm.ExecuteReader()

While (reader.Read)

tb2.Text = (reader("address"))

tb3.Text = (reader("phno"))

Dim s As String = (reader("status"))

If rb1.Text = s Then

rb1.Checked = True

Else

rb2.Checked = True

End If

End While

ComboBox1.Focus()

End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load

33 (Amit Rajput 06/CS/007)


Dim str2, str6 As String

str6 = "provider=microsoft.jet.oledb.4.0; data source=C:\Documents and


Settings\bsaitm\My Documents\db6.mdb"

conn = New OleDbConnection(str6)

conn.Open()

Dim reader As OleDbDataReader

Dim comm As New OleDbCommand

str2 = "select name from priya "

comm = New OleDbCommand(str2, conn)

reader = comm.ExecuteReader()

While (reader.read)

ComboBox1.Items.Add(reader("name"))

End While

reader.close()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click

Dim str4 As String

Dim k As String

Dim comm As New OleDbCommand

If rb1.Checked = True Then

k = "married"

Else

k = "unmarried"

34 (Amit Rajput 06/CS/007)


End If

str4 = "Update kavita set address='" & tb2.Text & "',phno='" & tb3.Text & "',status='" & k &
"' where name = '" & ComboBox1.SelectedItem & "' "

comm = New OleDbCommand(str4, conn)

comm.ExecuteNonQuery()

MsgBox("data updated successfully")

tb2.Clear()

tb3.Clear()

rb1.Checked = False

rb2.Checked = False

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click

Dim str5 As String

Dim comm As New OleDbCommand

str5 = "delete from priya where name='" & ComboBox1.SelectedItem & "' "

comm = New OleDbCommand(str5, conn)

comm.ExecuteNonQuery()

MsgBox("data deleted successfully")

tb2.Clear()

tb3.Clear()

rb1.Checked = False

rb2.Checked = False

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click

35 (Amit Rajput 06/CS/007)


Dim a As New Form1

a.Show()

Me.Hide()

conn.Close()

End Sub

End Class

OUTPUT:- ADO.NET CONNECTIVITY

36 (Amit Rajput 06/CS/007)


Program - 9
37 (Amit Rajput 06/CS/007)
Aim : To perform simple binding
Imports System.Data.OleDb

Public Class Form2

Dim cb As New OleDb.OleDbCommandBuilder(adap)

Dim dsnewrow As DataRow

Dim dt As DataTable

Dim conn As New OleDbConnection

Dim adap As OleDbDataAdapter

Dim ds As DataSet

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click

Me.BindingContext(ds, "table1").Position = 0

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click

Me.BindingContext(ds, "table1").Position += 1

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click

Me.BindingContext(ds, "table1").Position -= 1

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click

Me.BindingContext(ds, "table1").Position = Me.BindingContext(ds,


"table1").Count - 1

End Sub

38 (Amit Rajput 06/CS/007)


Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0.; data


source=C:\Documents and Settings\student\My Documents\db2.mdb")

Dim str As String = "select * from table1"

adap = New OleDbDataAdapter(str, conn)

ds = New DataSet

adap.Fill(ds, "table1")

TextBox1.DataBindings.Add("text", ds, "table1.name")

TextBox2.DataBindings.Add("text", ds, "table1.address")

TextBox3.DataBindings.Add("text", ds, "table1.age")

TextBox4.DataBindings.Add("text", ds, "table1.status")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

Dim cb As New OleDb.OleDbCommandBuilder(adap)

dt = ds.Tables("table1")

dsnewrow = dt.NewRow()

dsnewrow.Item("name") = TextBox1.Text

dsnewrow.Item("address") = TextBox2.Text

dsnewrow.Item("age") = TextBox3.Text

dsnewrow.Item("status") = TextBox4.Text

dt.Rows.Add(dsnewrow)

adap.Update(ds, "table1")

MsgBox("new record added to the database")

End Sub

39 (Amit Rajput 06/CS/007)


End Class

OUTPUT:- SIMPLE BINDING

Program - 10
Aim : To implement complex Binding
40 (Amit Rajput 06/CS/007)
Imports System.Data.OleDb

Public Class Form1

Dim conn As OleDbConnection

Dim adap As OleDbDataAdapter

Dim ds As DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0; data


source=C:\Documents and Settings\student\My Documents\db2.mdb")

Dim str As String

str = "select * from table1"

adap = New OleDbDataAdapter(str, conn)

ds = New DataSet

adap.Fill(ds, "table1")

DataGridView1.DataSource = ds.Tables("table1")

End Sub

End Class

OUTPUT:- COMPLEX BINDING

41 (Amit Rajput 06/CS/007)


42 (Amit Rajput 06/CS/007)

You might also like