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

GADPR

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)
11 views15 pages

GADPR

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
You are on page 1/ 15

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

Imports System.Data.OleDb
Public Class Form1

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


Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HARSHAD
THOK\OneDrive\Documents\Database5.accdb")
Dim cmd As New OleDbCommand("Select * from Student", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)

End Sub
End Class

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

Imports System.Data.OleDb
Public Class Form1

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


Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HARSHAD
THOK\OneDrive\Documents\Database5.accdb")
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
da.Fill(ds, "Student")
da1.Fill(ds, "Details")

DataGridView1.DataSource = ds.Tables("Student")
DataGridView2.DataSource = ds.Tables("Details")

End Sub
End Class
3) Imports System.Data.OleDb
Public Class Form1
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HARSHAD
THOK\OneDrive\Documents\Database5.accdb")

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


conn.Open()
Dim cmd As New OleDbCommand("Select * from Student", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "Student")
DataGridView1.DataSource = ds.Tables("Student")

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim en, n, c As String
Dim p As Integer
en = TextBox1.Text
n = TextBox2.Text
c = TextBox3.Text
p = Val(TextBox4.Text)
Dim cmd1 As New OleDbCommand("Insert into Student Values('" & en & "','" & n & "','" & c & "', " & p & ")",
conn)
cmd1.ExecuteNonQuery()

MessageBox.Show("Record Inserted Successfully")


End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


Dim en, n, c As String
Dim p As Integer
en = TextBox1.Text
n = TextBox2.Text
c = TextBox3.Text
p = Val(TextBox4.Text)
Dim cmd1 As New OleDbCommand("update Student set Name1='" & TextBox2.Text & "', Class='" &
TextBox3.Text & "', Percentage=" & Val(TextBox4.Text) & " WHERE Enrollment NO='" & TextBox1.Text & "'", conn)
cmd1.ExecuteNonQuery()
MessageBox.Show(cmd1.CommandText)
MessageBox.Show("Record Updated Successfully")
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


Dim en, n, c As String
Dim p As Integer
en = TextBox1.Text
n = TextBox2.Text
c = TextBox3.Text
p = Val(TextBox4.Text)
Dim cmd1 As New OleDbCommand("delete * from Student where Name1='" & n & "'", conn)
cmd1.ExecuteNonQuery()
MessageBox.Show("Record Deleted Successfully")
End Sub
End Class

4)Navigation
Imports System.Data.OleDb
Public Class Form1
Dim min As Integer = 0
Dim max As Integer

Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HARSHAD


THOK\OneDrive\Documents\Database5.accdb")
Dim ds As New DataSet
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conn.Open()
Dim cmd As New OleDbCommand("Select * from Student ", conn)
Dim da As New OleDbDataAdapter(cmd)

da.Fill(ds)
TextBox1.Text = ds.Tables(0).Rows(0).Item(0)
TextBox2.Text = ds.Tables(0).Rows(0).Item(1)
TextBox3.Text = ds.Tables(0).Rows(0).Item(2)
TextBox4.Text = ds.Tables(0).Rows(0).Item(3)
max = ds.Tables(0).Rows.Count
max = max - 1

End Sub
Public Sub nav(ByVal r As Integer)
TextBox1.Text = ds.Tables(0).Rows(r).Item(0)
TextBox2.Text = ds.Tables(0).Rows(r).Item(1)
TextBox3.Text = ds.Tables(0).Rows(r).Item(2)
TextBox4.Text = ds.Tables(0).Rows(r).Item(3)
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


min = 0

nav(min)

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


min = ds.Tables(0).Rows.Count
min = min - 1
nav(min)
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


If min = max Then
MessageBox.Show("Last Record")
Else
min = min + 1
nav(min)
End If

End Sub

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


If min = 0 Then
MessageBox.Show("First Record")
Else
min = min - 1
nav(min)
End If
End Sub
End Class

5)

complex binding

Imports System.Data.OleDb
Public Class Form1
Dim min As Integer = 0
Dim max As Integer

Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HARSHAD


THOK\OneDrive\Documents\Database5.accdb")
Dim ds As New DataSet

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


conn.Open()
Dim cmd As New OleDbCommand("Select * from Student ", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader
While dr.Read
CheckedListBox1.Items.Add(dr.Item(1))
End While

End Sub

End Class

6)simple binding

Imports System.Data.OleDb
Public Class Form1
Dim min As Integer = 0
Dim max As Integer

Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HARSHAD


THOK\OneDrive\Documents\Database5.accdb")
Dim ds As New DataSet

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


conn.Open()
Dim cmd As New OleDbCommand("Select * from Student ", conn)
Dim da As New OleDbDataAdapter(cmd)

da.Fill(ds, "Student")
TextBox1.Text = ds.Tables(0).Rows(0).Item(0)
TextBox2.DataBindings.Add("Text", ds, "Student.Name1")
TextBox3.Text = ds.Tables(0).Rows(0).Item(2)
TextBox4.Text = ds.Tables(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
Console.WriteLine("Enter Rollno and name:")
Rollno = Console.ReadLine()
Name = Console.ReadLine()
Console.WriteLine("Enter Age ")
age = Console.ReadLine()
If age <= 0 Then
Throw New Exception("Entered age is negative")
Else
Console.WriteLine("Regestaration Successful")
End If

Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

Console.ReadKey()
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
d.proc()
Console.ReadKey()

End Sub

End Module
Class base
Sub proc()
Console.WriteLine("Base class Method")
End Sub
End Class
Class derived
Inherits base
Shadows Sub proc()
Console.WriteLine("Derived Class Method")
MyBase.proc()
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()
Console.ReadKey()

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 = MyClass.temp
Console.WriteLine("Y=" & y)
Console.WriteLine("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()
MessageBox.Show("Concated String is:" & (s1 + s2))
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
concat(TextBox1.Text, TextBox2.Text)
concat()
End Sub
End Class
Output:

11)inheritance
Module Module1

Sub Main()
Dim s As New Student
s.accept1()
s.accept2()
s.display()
Console.ReadKey()
End Sub

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

ENter Name and age


M.P.Bhosale
40
ENter Name and class of student
Rutik
SYCM-LIN
Name of Faculty:M.P.Bhosale
Age of FAculty=40
Name OF Student=Rutik
Class Of Student=SYCM-LIN

12)constructor
Module Module1

Sub Main()
Dim radius As Integer
Console.WriteLine("Enter Radius:")
radius = Console.ReadLine()
Dim obj As New Area(radius)
Console.ReadKey()
End Sub

End Module
Class Area
Sub New(ByVal r As Integer)
Dim area As Double
area = 3.14 * r * r
Console.WriteLine("Area=" & area)
End Sub

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

Sub Main()
Dim radius As Integer
Console.WriteLine("Enter Radius:")
radius = Console.ReadLine()
Dim obj As New Area()
obj.Area(radius)
Console.ReadKey()
End Sub

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

14)class & obj

Module Module1

Sub Main()
Dim b As New Box
b.volume(3, 4, 5)
Console.ReadKey()

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
Console.WriteLine("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
Console.WriteLine("Enter the no:")
i = Console.ReadLine()
n = i
f = fact(i)
Console.WriteLine("Factorial of " & n & " is " & f)
Console.ReadKey()
End Sub
End Module

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

16) procedure

Imports System.Math
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 = Math.Floor(no / 10)

End While
Console.WriteLine("Reverse of no is " & rev)
End Sub
Sub main()

Console.WriteLine("Enter the no:")


i = Console.ReadLine()
reve(i)

Console.ReadKey()
End Sub
End Module
Output:
Enter the no:
567
Reverse of no is 765

17)
Validation
Imports System.Text.RegularExpressions
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
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If rm.IsMatch(TextBox1.Text) Then
ErrorProvider1.SetError(TextBox1, "")
Else
ErrorProvider1.SetError(TextBox1, "Please Enter valid Username ")
e.Cancel = True

End If
End Sub

Private Sub TextBox2_Validating(sender As Object, e As


System.ComponentModel.CancelEventArgs) Handles TextBox2.Validating
If rv.IsMatch(TextBox2.Text) Then
ErrorProvider1.SetError(TextBox2, "")
Else
ErrorProvider1.SetError(TextBox2, "Please Enter valid Password ")
e.Cancel = True

End If
End Sub

Private Sub TextBox3_Validating(sender As Object, e As


System.ComponentModel.CancelEventArgs) Handles TextBox3.Validating
If fv.IsMatch(TextBox3.Text) Then
ErrorProvider1.SetError(TextBox3, "")
Else
ErrorProvider1.SetError(TextBox3, "Please Enter valid Mobileno ")
e.Cancel = True

End If
End Sub

Private Sub TextBox4_Validating(sender As Object, e As


System.ComponentModel.CancelEventArgs) Handles TextBox4.Validating
If nv.IsMatch(TextBox4.Text) Then
ErrorProvider1.SetError(TextBox4, "")
Else
ErrorProvider1.SetError(TextBox4, "Please Enter valid Mobileno ")
e.Cancel = 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 MyBase.Load

End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
cnt = cnt + 1

Label1.Text = TimeOfDay
If cnt >= 0 And cnt <= 120 Then
OvalShape1.Visible = True
OvalShape2.Visible = False
OvalShape3.Visible = False
ElseIf cnt > 120 And cnt <= 150 Then
OvalShape1.Visible = False
OvalShape2.Visible = True
OvalShape3.Visible = False
ElseIf cnt > 150 And cnt <= 220 Then
OvalShape1.Visible = False
OvalShape2.Visible = False
OvalShape3.Visible = 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 MyBase.Load


PictureBox1.ImageLocation = "C:\Users\HARSHAD THOK\OneDrive\Pictures\buddha .jpg"

End Sub
End Class

You might also like