I have a question about the program that i made...i got vshost.exe has stopped working..
heres the problem i enter the data and the image because i make a student information system so i provide camera capturing ....now after i already input all the entry i'll save it and i have 1 messagebox that ask if you want to add another entry or not "yes/no" when i press no i got vshost.exe has stopped working instead go back into main form ....the next problem that i have encounter when i done saved the the first entry the data will be save now when click yes for me to add another data after all filled is complete and ready to save i got this error "attemped to read or protected memory. this is often an indicator that other memory is currupt"
Private Sub FrmEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If FormState = Form_State.Add_RecordState Then
Call ContextMnu()
Call CapsLock()
Call GenderItem()
Me.BSave.Text = "Save:"
Me.Text = "Add Record:"
Call ImageSyntax()
Try
With OleCn
If .State <> ConnectionState.Open Then
.ConnectionString = StrConnection()
.Open()
'Initialized Command...
With OleDa
.SelectCommand = New OleDbCommand()
.SelectCommand.CommandText = "SELECT * FROM [Employee]"
.SelectCommand.Connection = OleCn
End With
Call UpdateSyntax()
'Insert Command...
With OleDa
.InsertCommand = New OleDbCommand()
.InsertCommand.CommandText = "INSERT INTO [Employee] ([Employee_ID] , [FirstName] , [LastName] , [MiddleName] , [Gender] , [Date_Of_Birth] , " & _
"[Course] , [Major] , [Block] , [Address] , [Contact_Number] , [EmployeePic]) VALUES (@Employee_ID , @FirstName , @LastName , @MiddleName , @Gender , @Date_Of_Birth , " & _
"@Course , @Major , @Block , @Address , @Contact_Number , @EmployeePic)"
.InsertCommand.Connection = OleCn
.InsertCommand.Parameters.Add("@Employee_ID", OleDbType.VarWChar, 50, "Employee_ID")
.InsertCommand.Parameters.Add("@FirstName", OleDbType.VarWChar, 50, "FirstName")
.InsertCommand.Parameters.Add("@LastName", OleDbType.VarWChar, 50, "LastName")
.InsertCommand.Parameters.Add("@MiddleName", OleDbType.VarWChar, 50, "MiddleName")
.InsertCommand.Parameters.Add("@Gender", OleDbType.VarWChar, 50, "Gender")
.InsertCommand.Parameters.Add("@Date_Of_Birth", OleDbType.VarWChar, 50, "Date_Of_Birth")
.InsertCommand.Parameters.Add("@Course", OleDbType.VarWChar, 50, "Course")
.InsertCommand.Parameters.Add("@Major", OleDbType.VarWChar, 50, "Major")
.InsertCommand.Parameters.Add("@Block", OleDbType.VarWChar, 50, "Block")
.InsertCommand.Parameters.Add("@Address", OleDbType.VarWChar, 50, "Address")
.InsertCommand.Parameters.Add("@Contact_Number", OleDbType.VarWChar, 50, "Contact_Number")
.InsertCommand.Parameters.Add("@EmployeePic", OleDbType.LongVarBinary, 0, "EmployeePic")
End With
End If
End With
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical, "Error...")
Finally
OleCn.Close()
End Try
End If
KeyPreview = True
End Sub
Public Function ShowBindData(ByVal StrSql As String) As DataSet
If FormState = Form_State.Edit_RecordState Then
Call ContextMnu()
Call CapsLock()
Call GenderItem()
Me.BSave.Text = "Save Changes:"
Me.Text = "Edit Record:"
Try
With OleCn
If .State <> ConnectionState.Open Then
.ConnectionString = StrConnection()
.Open()
With OleDa
.SelectCommand = New OleDbCommand()
.SelectCommand.CommandText = "SELECT * FROM [Employee] WHERE (Employee_ID = @Employee_ID)"
.SelectCommand.Parameters.Add("@Employee_ID", OleDbType.VarChar, 50, "Employee_ID").Value = StrSql.ToString()
.SelectCommand.Connection = OleCn
End With
Call UpdateSyntax()
OleDa.Fill(DtaSet2, "Employee")
Me.TxtStudentID.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.Employee_ID", True))
Me.TxtFirstName.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.FirstName", True))
Me.TxtLastName.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.LastName", True))
Me.TxtMI.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.MiddleName", True))
Me.CBGender.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.Gender", True))
Me.DTDateOfBirth.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.Date_Of_Birth", True))
Me.TxtCourse.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.Course", True))
Me.TxtMajor.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.Major", True))
Me.TxtBlock.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.Block", True))
Me.TxtAddress.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.Address", True))
Me.TxtContactNumber.DataBindings.Add(New Binding("Text", DtaSet2, "Employee.Contact_Number", True))
Main = FrmMain
Me.PicStudent.Image = FrmMain.PictureBox1.Image
End If
End With
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical, "Error...")
Finally
OleCn.Close()
End Try
End If
Return DtaSet2
End Function
Private Sub UpdateSyntax()
'Syntax on how to Update without using CommandBuilder...
With OleDa
.UpdateCommand = New OleDbCommand()
.UpdateCommand.CommandText = "UPDATE [Employee] Set [Employee_ID] = @Employee_ID , [FirstName] = @FirstName , [LastName] = @LastName , [MiddleName] = @MiddleName , [Gender] = @Gender , " & _
"[Date_Of_Birth] = @Date_Of_Birth , [Course] = @Course , [Major] = @Major , [Block] = @Block , [Address] = @Address , [Contact_Number] = @Contact_Number , [EmployeePic] = @EmployeePic WHERE ([Employee_ID] = ?)"
.UpdateCommand.Connection = OleCn
.UpdateCommand.Parameters.Add("@Employee_ID", OleDbType.VarWChar, 50, "Employee_ID")
.UpdateCommand.Parameters.Add("@FirstName", OleDbType.VarWChar, 50, "FirstName")
.UpdateCommand.Parameters.Add("@LastName", OleDbType.VarWChar, 50, "LastName")
.UpdateCommand.Parameters.Add("@MiddleName", OleDbType.VarWChar, 50, "MiddleName")
.UpdateCommand.Parameters.Add("@Gender", OleDbType.VarWChar, 50, "Gender")
.UpdateCommand.Parameters.Add("@Date_Of_Birth", OleDbType.VarWChar, 50, "Date_Of_Birth")
.UpdateCommand.Parameters.Add("@Course", OleDbType.VarWChar, 50, "Course")
.UpdateCommand.Parameters.Add("@Major", OleDbType.VarWChar, 50, "Major")
.UpdateCommand.Parameters.Add("@Block", OleDbType.VarWChar, 50, "Block")
.UpdateCommand.Parameters.Add("@Address", OleDbType.VarWChar, 50, "Address")
.UpdateCommand.Parameters.Add("@Contact_Number", OleDbType.VarWChar, 50, "Contact_Number")
.UpdateCommand.Parameters.Add("@EmployeePic", OleDbType.LongVarBinary, 0, "EmployeePic")
.UpdateCommand.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Syntax_Employee_ID", OleDbType.VarWChar, 50, _
System.Data.ParameterDirection.Input, False, _
CType(0, Byte), CType(0, Byte), "Employee_ID", _
DataRowVersion.Original, Nothing)).Value = True
End With
End Sub
Private Function RequiredEntry() As Boolean
If TxtStudentID.Text = "" Or TxtFirstName.Text = "" Or TxtLastName.Text = "" Or _
TxtMI.Text = "" Or CBGender.Text = "" Or TxtCourse.Text = "" Or TxtMajor.Text = "" Or _
TxtBlock.Text = "" Or TxtAddress.Text = "" = True Then
MsgBox("Please enter required * information....", MsgBoxStyle.Critical, "Attention...")
Return True
Exit Function
End If
End Function
Private Sub BSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BSave.Click
Main = FrmMain
If FormState = Form_State.Add_RecordState Then
If RequiredEntry() = True Then
Return
End If
Try
Dim DtaRow As DataRow
Dim MemStream As New MemoryStream
Dim DataPic_Insert As Byte()
DtaRow = DtaSet.Tables("Employee").NewRow
DtaRow("Employee_ID") = IIf(TxtStudentID.Text = "", System.DBNull.Value, TxtStudentID.Text)
DtaRow("FirstName") = IIf(TxtFirstName.Text = "", System.DBNull.Value, TxtFirstName.Text)
DtaRow("LastName") = IIf(TxtLastName.Text = "", System.DBNull.Value, TxtLastName.Text)
DtaRow("MiddleName") = IIf(TxtMI.Text = "", System.DBNull.Value, TxtMI.Text)
DtaRow("Gender") = IIf(CBGender.Text = "", System.DBNull.Value, CBGender.Text)
DtaRow("Date_Of_Birth") = IIf(DTDateOfBirth.Text = "", System.DBNull.Value, DTDateOfBirth.Text)
DtaRow("Course") = IIf(TxtCourse.Text = "", System.DBNull.Value, TxtCourse.Text)
DtaRow("Major") = IIf(TxtMajor.Text = "", System.DBNull.Value, TxtMajor.Text)
DtaRow("Block") = IIf(TxtBlock.Text = "", System.DBNull.Value, TxtBlock.Text)
DtaRow("Address") = IIf(TxtAddress.Text = "", System.DBNull.Value, TxtAddress.Text)
DtaRow("Contact_Number") = IIf(TxtContactNumber.Text = "", System.DBNull.Value, TxtContactNumber.Text)
Me.PicStudent.Image.Save(MemStream, Imaging.ImageFormat.Png) 'Jpeg, Bmp , Gif , Tiff Etc.....
DataPic_Insert = MemStream.GetBuffer() 'or .ToArray()
DtaRow("EmployeePic") = DataPic_Insert
DtaSet.Tables("Employee").Rows.Add(DtaRow)
OleDa.Update(DtaSet, "Employee")
DtaSet.AcceptChanges()
'Focus the Added record...
With Main
.BindingContext.Item(DtaSet, "Employee").Position = Main.BindingContext.Item(DtaSet, "Employee").Count - 1
Call .Navigation()
End With
MsgBox("Record's successfully saved...", MsgBoxStyle.Information, "Record's saved...")
If MsgBox("Do you want to add new record?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirmation...") = MsgBoxResult.Yes Then
Call ResetEntry()
TxtStudentID.Focus()
Exit Sub
End If
Me.Close()
Catch ex As Exception
MsgBox("Unable to save new record, Employee ID already exist, please enter another Employee ID...", MsgBoxStyle.Critical, "Attention...")
TxtStudentID.Focus()
TxtStudentID.SelectAll()
DtaSet.RejectChanges()
End Try
Exit Sub
End If
If FormState = Form_State.Edit_RecordState Then
If RequiredEntry() = True Then
Return
End If
Try
Dim MemStream As New MemoryStream
Dim DataPic_Update As Byte()
OleDa.Fill(DtaSet2, "Employee")
With DtaSet2
.Tables("Employee").Rows(0).Item("Employee_ID") = IIf(TxtStudentID.Text = "", System.DBNull.Value, TxtStudentID.Text)
.Tables("Employee").Rows(0).Item("FirstName") = IIf(TxtFirstName.Text = "", System.DBNull.Value, TxtFirstName.Text)
.Tables("Employee").Rows(0).Item("LastName") = IIf(TxtLastName.Text = "", System.DBNull.Value, TxtLastName.Text)
.Tables("Employee").Rows(0).Item("MiddleName") = IIf(TxtMI.Text = "", System.DBNull.Value, TxtMI.Text)
.Tables("Employee").Rows(0).Item("Gender") = IIf(CBGender.Text = "", System.DBNull.Value, CBGender.Text)
.Tables("Employee").Rows(0).Item("Date_Of_Birth") = IIf(DTDateOfBirth.Text = "", System.DBNull.Value, DTDateOfBirth.Text)
.Tables("Employee").Rows(0).Item("Course") = IIf(TxtCourse.Text = "", System.DBNull.Value, TxtCourse.Text)
.Tables("Employee").Rows(0).Item("Major") = IIf(TxtMajor.Text = "", System.DBNull.Value, TxtMajor.Text)
.Tables("Employee").Rows(0).Item("Block") = IIf(TxtBlock.Text = "", System.DBNull.Value, TxtBlock.Text)
.Tables("Employee").Rows(0).Item("Address") = IIf(TxtAddress.Text = "", System.DBNull.Value, TxtAddress.Text)
.Tables("Employee").Rows(0).Item("Contact_Number") = IIf(TxtContactNumber.Text = "", System.DBNull.Value, TxtContactNumber.Text)
Me.PicStudent.Image.Save(MemStream, Imaging.ImageFormat.Png) 'Jpeg, Bmp , Gif , Tiff Etc.....
DataPic_Update = MemStream.GetBuffer() 'or .ToArray()
.Tables("Employee").Rows(0).Item("EmployeePic") = DataPic_Update
.Tables("Employee").Rows(0).Item("Employee_ID", DataRowVersion.Original).ToString()
End With
'Focus updated record without load or refresh...
With Main
With .DgV
.SelectedRows(0).Cells(0).Value = Me.TxtStudentID.Text
.SelectedRows(0).Cells(1).Value = Me.TxtFirstName.Text
.SelectedRows(0).Cells(2).Value = Me.TxtLastName.Text
.SelectedRows(0).Cells(3).Value = Me.TxtMI.Text
.SelectedRows(0).Cells(4).Value = Me.CBGender.Text
.SelectedRows(0).Cells(5).Value = Me.DTDateOfBirth.Text
.SelectedRows(0).Cells(6).Value = Me.TxtCourse.Text
.SelectedRows(0).Cells(7).Value = Me.TxtMajor.Text
.SelectedRows(0).Cells(8).Value = Me.TxtBlock.Text
End With
.PictureBox1.Image = Me.PicStudent.Image
End With
BindingContext(DtaSet2, "Employee").EndCurrentEdit()
If DtaSet2.HasChanges() Then
OleDa.Update(DtaSet2, "Employee")
DtaSet2.AcceptChanges()
End If
MsgBox("Record's successfully updated...", MsgBoxStyle.Information, "Record's Updated...")
Catch ex As Exception
MsgBox("Unable to update, Employee ID already exist...", MsgBoxStyle.Critical, "Attention...")
DtaSet2.RejectChanges()
'Back to updated Student ID
Main.DgV.SelectedRows(0).Cells(0).Value = Me.TxtStudentID.Text
End Try
Exit Sub
End If
End Sub
I include all the code for you to see the main error to my code i wonder because i can save in the first entry but when i enter another entry i got the error...

New Topic/Question
Reply



MultiQuote




|