Professional Documents
Culture Documents
OleDb
Imports System.IO
Public Class StudRegister
Dim er, pho As Integer
End Sub
Module1.conn()
cn.Open()
er = 0
'cn.Open()
str = "select * from Student"
cmd = New OleDbCommand(str, cn)
da.SelectCommand = cmd
da.Fill(ds, "Student")
ds.Clear()
str = "select * from Student"
cmd = New OleDbCommand(str, cn)
da.SelectCommand = cmd
da.Fill(ds, "Student")
Dim LastNo As Integer
Dim ph As String
LastNo = ds.Tables("Student").Rows.Count + 1
If LastNo >= 0 Then
ph = "PH" & LastNo
Else
ph = "PH" & 0
End If
'insert
If er = 0 Then
Try
cmd.Connection = cn
cmd.CommandText = "insert into
Student(RegNo,StudName,DateAdd,DOB,Age,Gender,PrAddress,PeAddress,FName,FMobile,FOc
cupation,MName,MMobile,MOccupation,Nationality,Area,BPlace,Religion,AdmitedTo,RollN
o) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & DateTimePicker1.Text
& "','" & DateTimePicker2.Text & "','" & TextBox3.Text & "','" & ComboBox2.Text &
"','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" &
TextBox8.Text & "','" & TextBox7.Text & "', '" & TextBox9.Text & "', '" &
TextBox11.Text & "', '" & TextBox10.Text & "', '" & ComboBox3.Text & "', '" &
ComboBox1.Text & "', '" & TextBox12.Text & "', '" & TextBox13.Text & "', '" &
ComboBox4.Text & "', '" & TextBox14.Text & "')"
cmd.ExecuteNonQuery()
If pho = 1 Then
'Photo Saving
cmd = New OleDbCommand
cmd.CommandText = " insert into Photo values (@PID, @SID,
@SName, @StudImage) "
cmd.Parameters.AddWithValue("@PID", ph)
cmd.Parameters.AddWithValue("@SID", TextBox1.Text)
cmd.Parameters.AddWithValue("@SName", TextBox2.Text)
Photos1 = File.ReadAllBytes(OpenFileDialog1.FileName)
cmd.Parameters.AddWithValue("@StudImage", Photos1)
cmd.Connection = cn
cmd.ExecuteNonQuery()
End If
'MsgBox("New Class Added.")
Dim result As Integer = MessageBox.Show("New Student Added. Want To
Add Another One.", "Added", MessageBoxButtons.YesNo)
If result = DialogResult.No Then
Me.Close()
ElseIf result = DialogResult.Yes Then
ds.Clear()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox9.Clear()
TextBox10.Clear()
TextBox11.Clear()
TextBox12.Clear()
TextBox13.Clear()
TextBox14.Clear()
ComboBox1.ResetText()
ComboBox2.ResetText()
ComboBox3.ResetText()
ComboBox4.ResetText()
pho = 1
End If
End Sub
End Class