0% found this document useful (0 votes)
3 views

.Net

The document outlines a Visual Basic .NET application for managing student information, including functionalities for uploading images and documents, selecting caste and branch details, and inserting data into a MySQL database. It features event handlers for various UI components like ComboBoxes, TextBoxes, and Buttons to facilitate user interactions. The application also includes error handling and connection management for database operations.

Uploaded by

dasmitag147
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

.Net

The document outlines a Visual Basic .NET application for managing student information, including functionalities for uploading images and documents, selecting caste and branch details, and inserting data into a MySQL database. It features event handlers for various UI components like ComboBoxes, TextBoxes, and Buttons to facilitate user interactions. The application also includes error handling and connection management for database operations.

Uploaded by

dasmitag147
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Code:

Imports MySql.Data.MySqlClient

Public Class Form2


Dim imgpath As String

Private Sub Button1_Click(sender As Object, e As EventArgs)

End Sub

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


ComboBox1.DrawMode = DrawMode.Normal

' Hard-coded example: add cast names to the ComboBox


ComboBox1.Items.AddRange({"OBC", "NT-A", "NT-B", "ST", "SC", "OPEN"})

ComboBox2.DrawMode = DrawMode.Normal

' Hard-coded example: add cast names to the ComboBox


ComboBox2.Items.AddRange({"Mechanical", "Electrical", "Civil", "Computer Science",
"IT", "Electronics"})

' hide Cast Document Upload label, textbox and button'


Label16.Visible = False
TextBox7.Visible = False
Button1.Visible = False
End Sub

Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs)

End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles


ComboBox1.SelectedIndexChanged

If ComboBox1.SelectedIndex <> -1 Then


Dim selectedCastName As String = ComboBox1.SelectedItem.ToString()
' Display the selected cast name in the ComboBox
ComboBox1.Text = selectedCastName

' Add your additional code here if needed


End If
End Sub

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


Try
Dim ofd As New OpenFileDialog()

' Set the filter to allow only image files


ofd.Filter = "Image Files (*.jpg;*.png;*.jpeg)|*.jpg;*.png;*.jpeg"

' Show the file dialog and check if the user selected a file
If ofd.ShowDialog() = DialogResult.OK Then
' Get the file path of the selected image and set it to the PictureBox
PictureBox1.ImageLocation = ofd.FileName
End If

' Dispose the file dialog object


ofd.Dispose()
Catch ex As Exception
' Display an error message if an exception occurs
MsgBox(ex.Message)
End Try
End Sub

Private Sub Label9_Click(sender As Object, e As EventArgs) Handles Label9.Click

End Sub

Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

End Sub

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


OpenFileDialog2.Filter = "PDF Files|*.pdf"

If OpenFileDialog2.ShowDialog() = DialogResult.OK Then


' Get the selected PDF file path
Dim pdfFilePath As String = OpenFileDialog2.FileName

' Display the file path in a TextBox


TextBox7.Text = pdfFilePath
End If
End Sub

Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles


TextBox7.TextChanged

End Sub

Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles


ComboBox2.SelectedIndexChanged
If ComboBox2.SelectedIndex <> -1 Then
Dim selectedCastName As String = ComboBox2.SelectedItem.ToString()
' Display the selected cast name in the ComboBox
ComboBox2.Text = selectedCastName

' Add your additional code here if needed


End If
End Sub

Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton1.CheckedChanged
If RadioButton1.Checked Then
' Show the label, textbox, and button
Label16.Visible = True
TextBox7.Visible = True
Button1.Visible = True
End If
End Sub

Private Sub CheckConnection()


Try
conn.Open()

If conn.State = ConnectionState.Open Then


'' MessageBox.Show("Connected to the database.", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Failed to connect to the database.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
' Always close the connection to release resources
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End Try
End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton2.CheckedChanged
If RadioButton2.Checked Then
' Hide the label, textbox, and button
Label16.Visible = False
TextBox7.Visible = False
Button1.Visible = False
End If
End Sub
Dim connectionString As String = "server=localhost;user
id=root;password=1234;database=student_management_system"
Dim conn As New MySqlConnection(connectionString)

Private Sub button3_Click(sender As Object, e As EventArgs) Handles button3.Click


Try
Dim arrimage() As Byte

CheckConnection()
Dim msstream As New System.IO.MemoryStream()
PictureBox1.Image.Save(msstream, System.Drawing.Imaging.ImageFormat.Jpeg)
arrimage = msstream.ToArray()
msstream.Close()

conn.Open()

Dim command As New MySqlCommand("INSERT INTO student_info (photo, name,


address, contact_no, adhar_no, caste, caste_certificate, document, branch_name,
college_name, admission_date, fees, year) VALUES (@photo, @name, @address,
@contact_no, @adhar_no, @caste, @caste_certificate, @document, @branch_name,
@college_name, @admission_date, @fees, @year)", conn)

command.Parameters.AddWithValue("@photo", arrimage)
command.Parameters.AddWithValue("@name", txtPassword.Text)
command.Parameters.AddWithValue("@address", TextBox1.Text)
command.Parameters.AddWithValue("@contact_no", TextBox2.Text)
command.Parameters.AddWithValue("@adhar_no", TextBox3.Text)
command.Parameters.AddWithValue("@caste", ComboBox1.Text)
If RadioButton1.Checked Then
command.Parameters.AddWithValue("@caste_certificate", "Yes")
ElseIf RadioButton2.Checked Then
command.Parameters.AddWithValue("@caste_certificate", "No")
End If

' Add the remaining parameters (adjust the names accordingly)


command.Parameters.AddWithValue("@document", TextBox7.Text)
command.Parameters.AddWithValue("@branch_name", ComboBox2.Text)
command.Parameters.AddWithValue("@college_name", "bhausaheb vartak
polytechnic")
command.Parameters.AddWithValue("@admission_date",
DateTimePicker1.Value.ToString("yyyy-MM-dd"))
command.Parameters.AddWithValue("@fees", Convert.ToInt32(TextBox5.Text))
command.Parameters.AddWithValue("@year", TextBox6.Text)

' Execute the command to insert data into the database


Dim x As Integer = command.ExecuteNonQuery()

If x > 0 Then
MessageBox.Show("Data Inserted")
Me.Hide()

Dim Form1 As New Form1()


Form1.ShowDialog()
Else
MessageBox.Show("Data Not Inserted")
End If

Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
Finally
conn.Close()
End Try
End Sub

Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click

End Sub

Private Sub txtPassword_TextChanged(sender As Object, e As EventArgs) Handles


txtPassword.TextChanged

End Sub

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles


TextBox1.TextChanged

End Sub

Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles


TextBox2.TextChanged

End Sub

Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles


TextBox3.TextChanged

End Sub

Private Sub TextBox4_TextChanged_1(sender As Object, e As EventArgs)

End Sub

Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles


DateTimePicker1.ValueChanged

End Sub

Private Sub Label2_Click(sender As Object, e As EventArgs)

End Sub

Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click


Me.Hide()
Dim Form1 As New Form1()
Form1.ShowDialog()
End Sub

Private Sub Label11_Click(sender As Object, e As EventArgs) Handles Label11.Click

End Sub

Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click

End Sub

Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

End Sub

Private Sub Panel3_Paint(sender As Object, e As PaintEventArgs) Handles Panel3.Paint

End Sub
End Class

Output:
1.Login page
2.Home Page

3. Add student
4. Student List

5.Student Detail
6.Update

7. Delete

You might also like