-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm2.vb
More file actions
80 lines (63 loc) · 2.97 KB
/
Form2.vb
File metadata and controls
80 lines (63 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Imports System.Data.SqlClient
Public Class Shoedetails
Private Sqlconstring As String = "Data Source=TERMINATOR\MSSQLSERVER05;Initial Catalog=Fashion_Feet;Integrated Security=True;Encrypt=False;Trust Server Certificate=True"
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadData()
End Sub
Private Sub LoadData()
Dim query As String = "SELECT * FROM Shoe Table"
Dim connection As New SqlConnection("Data Source=TERMINATOR\MSSQLSERVER05;Initial Catalog=Fashion_Feet;Integrated Security=True;Encrypt=False")
Dim adapter As New SqlDataAdapter(query, connection)
Dim dataTable As New DataTable()
Try
connection.Open()
adapter.Fill(dataTable)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
Finally
connection.Close()
End Try
End Sub
Private Sub Cancel_Click(sender As Object, e As EventArgs) Handles Cancel.Click
TextBox1.Text = String.Empty
ComboBox1.Text = String.Empty
ComboBox2.Text = String.Empty
ComboBox3.Text = String.Empty
ComboBox4.Text = String.Empty
ComboBox5.Text = String.Empty
TextBox2.Text = String.Empty
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Back.Click
Me.Hide()
Dim Dashboard As New Dashboard
Dashboard.Show()
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub OK_Click(sender As Object, e As EventArgs) Handles OK.Click
Dim query As String = "INSERT INTO
Shoe Table(Shoe ID, Brand, Model, Size,color, quantity, Price)VALUES
(@Shoe ID,@Brand,@Model,@Size,@Color,@quantity,@Price)"
Dim connection As New SqlConnection("Data Source=TERMINATOR\MSSQLSERVER05;Initial Catalog=Fashion_Feet;Integrated Security=True;Encrypt=False;Trust Server Certificate=True")
Dim command As New SqlCommand(query, connection)
command.Parameters.AddWithValue("@Shoe ID", TextBox1.Text)
command.Parameters.AddWithValue("@Brand", ComboBox1.Text)
command.Parameters.AddWithValue("@Model", ComboBox2.Text)
command.Parameters.AddWithValue("@Size", ComboBox3.Text)
command.Parameters.AddWithValue("@Color", ComboBox4.Text)
command.Parameters.AddWithValue("@quantity", ComboBox5.Text)
command.Parameters.AddWithValue("@Price", TextBox2.Text)
Try
connection.Open()
command.ExecuteNonQuery()
MessageBox.Show("Data inserted successfully.")
LoadData() ' Reload data after insertion
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
Finally
connection.Close()
End Try
End Sub
End Class