0% found this document useful (0 votes)
33 views15 pages

Windows App for Data Binding and CRUD

The documents describe how to design windows applications to display data from databases in data grids and tables. It includes examples of connecting to databases, selecting data, displaying multiple tables, adding navigation controls, and handling events like inserting, updating, and deleting records. Object-oriented programming concepts like inheritance, constructors, and exception handling are also demonstrated.

Uploaded by

shantanukapse76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views15 pages

Windows App for Data Binding and CRUD

The documents describe how to design windows applications to display data from databases in data grids and tables. It includes examples of connecting to databases, selecting data, displaying multiple tables, adding navigation controls, and handling events like inserting, updating, and deleting records. Object-oriented programming concepts like inheritance, constructors, and exception handling are also demonstrated.

Uploaded by

shantanukapse76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1)Design a windows application that display the table on data grid view

Imports [Link]
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]


Dim conn As New OleDbConnection("Provider=[Link].12.0;Data Source=C:\Users\HARSHAD
THOK\OneDrive\Documents\[Link]")
Dim cmd As New OleDbCommand("Select * from Student", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
[Link](ds)
[Link] = [Link](0)

End Sub
End Class

2) Design a windows application that display multiple table on data grid view

Imports [Link]
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]


Dim conn As New OleDbConnection("Provider=[Link].12.0;Data Source=C:\Users\HARSHAD
THOK\OneDrive\Documents\[Link]")
Dim cmd As New OleDbCommand("Select * from Student", conn)
Dim cmd1 As New OleDbCommand("Select * from Details", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim da1 As New OleDbDataAdapter(cmd1)
Dim ds As New DataSet
[Link](ds, "Student")
[Link](ds, "Details")

[Link] = [Link]("Student")
[Link] = [Link]("Details")

End Sub
End Class
3) Imports [Link]
Public Class Form1
Dim conn As New OleDbConnection("Provider=[Link].12.0;Data Source=C:\Users\HARSHAD
THOK\OneDrive\Documents\[Link]")

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]


[Link]()
Dim cmd As New OleDbCommand("Select * from Student", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
[Link](ds, "Student")
[Link] = [Link]("Student")

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]


Dim en, n, c As String
Dim p As Integer
en = [Link]
n = [Link]
c = [Link]
p = Val([Link])
Dim cmd1 As New OleDbCommand("Insert into Student Values('" & en & "','" & n & "','" & c & "', " & p & ")",
conn)
[Link]()

[Link]("Record Inserted Successfully")


End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]


Dim en, n, c As String
Dim p As Integer
en = [Link]
n = [Link]
c = [Link]
p = Val([Link])
Dim cmd1 As New OleDbCommand("update Student set Name1='" & [Link] & "', Class='" &
[Link] & "', Percentage=" & Val([Link]) & " WHERE Enrollment NO='" & [Link] & "'", conn)
[Link]()
[Link]([Link])
[Link]("Record Updated Successfully")
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]


Dim en, n, c As String
Dim p As Integer
en = [Link]
n = [Link]
c = [Link]
p = Val([Link])
Dim cmd1 As New OleDbCommand("delete * from Student where Name1='" & n & "'", conn)
[Link]()
[Link]("Record Deleted Successfully")
End Sub
End Class

4)Navigation
Imports [Link]
Public Class Form1
Dim min As Integer = 0
Dim max As Integer

Dim conn As New OleDbConnection("Provider=[Link].12.0;Data Source=C:\Users\HARSHAD


THOK\OneDrive\Documents\[Link]")
Dim ds As New DataSet
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
[Link]()
Dim cmd As New OleDbCommand("Select * from Student ", conn)
Dim da As New OleDbDataAdapter(cmd)

[Link](ds)
[Link] = [Link](0).Rows(0).Item(0)
[Link] = [Link](0).Rows(0).Item(1)
[Link] = [Link](0).Rows(0).Item(2)
[Link] = [Link](0).Rows(0).Item(3)
max = [Link](0).[Link]
max = max - 1

End Sub
Public Sub nav(ByVal r As Integer)
[Link] = [Link](0).Rows(r).Item(0)
[Link] = [Link](0).Rows(r).Item(1)
[Link] = [Link](0).Rows(r).Item(2)
[Link] = [Link](0).Rows(r).Item(3)
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]


min = 0

nav(min)

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]


min = [Link](0).[Link]
min = min - 1
nav(min)
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]


If min = max Then
[Link]("Last Record")
Else
min = min + 1
nav(min)
End If

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles [Link]


If min = 0 Then
[Link]("First Record")
Else
min = min - 1
nav(min)
End If
End Sub
End Class

5)

complex binding

Imports [Link]
Public Class Form1
Dim min As Integer = 0
Dim max As Integer

Dim conn As New OleDbConnection("Provider=[Link].12.0;Data Source=C:\Users\HARSHAD


THOK\OneDrive\Documents\[Link]")
Dim ds As New DataSet

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]


[Link]()
Dim cmd As New OleDbCommand("Select * from Student ", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim dr As OleDbDataReader
dr = [Link]
While [Link]
[Link]([Link](1))
End While

End Sub

End Class

6)simple binding

Imports [Link]
Public Class Form1
Dim min As Integer = 0
Dim max As Integer

Dim conn As New OleDbConnection("Provider=[Link].12.0;Data Source=C:\Users\HARSHAD


THOK\OneDrive\Documents\[Link]")
Dim ds As New DataSet

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]


[Link]()
Dim cmd As New OleDbCommand("Select * from Student ", conn)
Dim da As New OleDbDataAdapter(cmd)

[Link](ds, "Student")
[Link] = [Link](0).Rows(0).Item(0)
[Link]("Text", ds, "Student.Name1")
[Link] = [Link](0).Rows(0).Item(2)
[Link] = [Link](0).Rows(0).Item(3)

End Sub

End Class
7)Exception Handaling

Module Module1

Sub Main()
Dim Rollno, age As Integer
Dim Name As String

Try
[Link]("Enter Rollno and name:")
Rollno = [Link]()
Name = [Link]()
[Link]("Enter Age ")
age = [Link]()
If age <= 0 Then
Throw New Exception("Entered age is negative")
Else
[Link]("Regestaration Successful")
End If

Catch ex As Exception
[Link]([Link])
End Try

[Link]()
End Sub

End Module
Output:

1)Enter Rollno and name:


56
HArshad
Enter Age
17
Regestaration Successful
2) Enter Rollno and name:
56
Harshad
Enter Age
0
Entered age is negative

8)through inheritance
Module Module1
Sub Main()
Dim d As New derived
[Link]()
[Link]()

End Sub

End Module
Class base
Sub proc()
[Link]("Base class Method")
End Sub
End Class
Class derived
Inherits base
Shadows Sub proc()
[Link]("Derived Class Method")
[Link]()
End Sub
End Class
Output:
Derived Class Method
Base class Method

9)through Scope
Module Module1

Sub Main()
Dim z As New class1
z.p()
[Link]()

End Sub

End Module
Class class1
Public temp As Integer = 5
Sub p()
Dim temp As Integer = 10
Dim y As Integer = temp
Dim z As Integer = [Link]
[Link]("Y=" & y)
[Link]("Z=" & z)
End Sub
End Class
Output:
Y=10
Z=5

10)overload
Public Class Form1
Dim s1, s2 As String
Public Overloads Sub concat(ByVal str1 As String, ByVal str2 As String)
s1 = str1
s2 = str2

End Sub
Public Overloads Sub concat()
[Link]("Concated String is:" & (s1 + s2))
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
concat([Link], [Link])
concat()
End Sub
End Class
Output:

11)inheritance
Module Module1

Sub Main()
Dim s As New Student
s.accept1()
s.accept2()
[Link]()
[Link]()
End Sub

End Module
Public Class Faculty
Public n As String
Public a As Integer
Sub accept1()
[Link]("ENter Name and age")
n = [Link]()
a = [Link]()
End Sub
End Class
Class Student
Inherits Faculty
Dim n1, c As String
Public Sub accept2()
[Link]("ENter Name and class of student")
n1 = [Link]()
c = [Link]()
End Sub
Sub display()
[Link]("Name of Faculty:" & n)
[Link]("Age of FAculty=" & a)
[Link]("Name OF Student=" & n1)
[Link]("Class Of Student=" & c)
End Sub
End Class
Output:

ENter Name and age


[Link]
40
ENter Name and class of student
Rutik
SYCM-LIN
Name of Faculty:[Link]
Age of FAculty=40
Name OF Student=Rutik
Class Of Student=SYCM-LIN

12)constructor
Module Module1

Sub Main()
Dim radius As Integer
[Link]("Enter Radius:")
radius = [Link]()
Dim obj As New Area(radius)
[Link]()
End Sub

End Module
Class Area
Sub New(ByVal r As Integer)
Dim area As Double
area = 3.14 * r * r
[Link]("Area=" & area)
End Sub

End Class
Output:
Enter Radius:
5
Area=78.5
13)destructor
Module Module1

Sub Main()
Dim radius As Integer
[Link]("Enter Radius:")
radius = [Link]()
Dim obj As New Area()
[Link](radius)
[Link]()
End Sub

End Module
Class Area
Sub Area(ByVal r As Integer)
Dim area As Double
area = 3.14 * r * r
[Link]("Area=" & area)
End Sub
Protected Overrides Sub finalize()
[Link]("Destructor Call")
End Sub
End Class

14)class & obj

Module Module1

Sub Main()
Dim b As New Box
[Link](3, 4, 5)
[Link]()

End Sub

End Module
Class Box
Sub volume(ByVal l As Integer, ByVal b As Integer, ByVal h As Integer)
Dim v As Double
v = l * b * h
[Link]("Volume=" & v)
End Sub

End Class

Output:
Volume=60

15)
Module Module1
Dim i As Integer
Public Function fact(ByVal no As Integer)
i = no
If i = 1 Then
Return 1
Else
Return i * fact(i - 1)
End If

End Function
Sub main()
Dim f, n As Integer
[Link]("Enter the no:")
i = [Link]()
n = i
f = fact(i)
[Link]("Factorial of " & n & " is " & f)
[Link]()
End Sub
End Module

Output:
Enter the no:
5
Factorial of 5 is 120

16) procedure

Imports [Link]
Module Module1
Dim i, rev, digit As Integer
Public Sub reve(ByVal no As Integer)
While (no > 0)
digit = no Mod 10
rev = rev * 10 + digit
no = [Link](no / 10)

End While
[Link]("Reverse of no is " & rev)
End Sub
Sub main()

[Link]("Enter the no:")


i = [Link]()
reve(i)

[Link]()
End Sub
End Module
Output:
Enter the no:
567
Reverse of no is 765

17)
Validation
Imports [Link]
Public Class Form1
Dim rm As New Regex("^[A-Z][a-zA-z0-9_]{5,15}$")
Dim rv As New Regex("^[a-zA-z0-9_@]{8,15}$")
Dim fv As New Regex("^[0-9]{10}$")
Dim nv As New Regex("^[a-zA-Z0-9+_.]+@[a-zA-z0-9._]+[.][a-zA-Z]{2,3}$")
Private Sub TextBox1_Validating(sender As Object, e As
[Link]) Handles [Link]
If [Link]([Link]) Then
[Link](TextBox1, "")
Else
[Link](TextBox1, "Please Enter valid Username ")
[Link] = True

End If
End Sub

Private Sub TextBox2_Validating(sender As Object, e As


[Link]) Handles [Link]
If [Link]([Link]) Then
[Link](TextBox2, "")
Else
[Link](TextBox2, "Please Enter valid Password ")
[Link] = True

End If
End Sub

Private Sub TextBox3_Validating(sender As Object, e As


[Link]) Handles [Link]
If [Link]([Link]) Then
[Link](TextBox3, "")
Else
[Link](TextBox3, "Please Enter valid Mobileno ")
[Link] = True

End If
End Sub

Private Sub TextBox4_Validating(sender As Object, e As


[Link]) Handles [Link]
If [Link]([Link]) Then
[Link](TextBox4, "")
Else
[Link](TextBox4, "Please Enter valid Mobileno ")
[Link] = True

End If
End Sub
End Class
18)Timer control
Public Class Form1
Dim cnt As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles [Link]
cnt = cnt + 1

[Link] = TimeOfDay
If cnt >= 0 And cnt <= 120 Then
[Link] = True
[Link] = False
[Link] = False
ElseIf cnt > 120 And cnt <= 150 Then
[Link] = False
[Link] = True
[Link] = False
ElseIf cnt > 150 And cnt <= 220 Then
[Link] = False
[Link] = False
[Link] = True
Else
cnt = 0
End If

End Sub

End Class
19)picture box
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]


[Link] = "C:\Users\HARSHAD THOK\OneDrive\Pictures\buddha .jpg"

End Sub
End Class

You might also like