visual basic and microsoft access database connection - visual-studio

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Database4DataSet.Table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Database4DataSet.Table1)
End Sub
Private Sub BtnPrevious_Click(sender As Object, e As EventArgs) Handles BtnPrevious.Click
Table1BindingSource.MovePrevious()
End Sub
Private Sub btnfirst_Click(sender As Object, e As EventArgs) Handles btnfirst.Click
Table1BindingSource.MoveFirst()
End Sub
Private Sub BtnNext_Click(sender As Object, e As EventArgs) Handles BtnNext.Click
Table1BindingSource.MoveNext()
End Sub
Private Sub BtnLast_Click(sender As Object, e As EventArgs) Handles BtnLast.Click
Table1BindingSource.MoveLast()
End Sub
Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
Table1BindingSource.AddNew()
End Sub
Private Sub btndelete_Click(sender As Object, e As EventArgs) Handles btndelete.Click
Table1BindingSource.RemoveCurrent()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Me.Validate()
Me.Table1BindingSource.EndEdit()
Me.Table1TableAdapter.Update(Me.Database4DataSet)
MsgBox("Your information has been saved successfully")
Catch ex As Exception
MsgBox("Please try again")
End Try
End Sub
Hi i am trying to create a simple vb application that connects to a Microsoft access database that stores basic information of student name, id number and result. my code is working to an extent but when i run the program and add new records the new data i entered saves no problem and i can see while the program is running but when i stop de bugging and start de bugging again the new information i added to the database the last time doesn't appear. only the information that i inputted originally into the database through the access file show up. any info or help would be appreciated.

Related

show confirm close message in all project forms vb.net?

I have Project containing multi forms
main page and others inside main page
used next code to make confirm close in main page
Public Sub MyForm_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles MyBase.FormClosing
If MessageBox.Show("Do you want to close the form?", "Confirm", MessageBoxButtons.YesNo) <> DialogResult.Yes Then
e.Cancel = True
End If
End Sub
and want the confirm message to show in all forms not only main page !
Here is a process I use because MessageBox while it is nice I like to design my own.
You will see some variables in the code that look like this
Public gvalertType As String
Public gvRESEdit As String
These are declared in a Module
Now we need some code for the frmAlert You will use If and ElseIf to trap multiple errors. I will post a screen shot of the frmAlert
Private Sub frmAlert_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If gvalertType = "10" Then
btnNO.Visible = True
lblAI.Text = " Caution "
tbAlert.Text = "OK To Delete " & vbCrLf & vbCrLf & "NO Do NOT Delete"
End If
End Sub
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
If btnNO.Visible = True Then
gvRESDelete = "YES"
End If
Close()
End Sub
Private Sub btnNO_Click(sender As Object, e As EventArgs) Handles btnNO.Click
gvRESDelete = "NO"
Close()
End Sub
OK Now on the form and button click that calls the frmAlert.
Because you are changing forms this is why the variables are declared in a Module.
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
gvalertType = "10"
frmAlert.ShowDialog()
If gvRESDelete = "NO" Then
btnBack.Focus()
Return
End If
If gvRESDelete = "YES" Then
DeleteSiteData()
End If
End Sub

How do i implement a pop out in panel like that of avast 9 application

How do i implement a pop out in panel like that of avast 9 application.
I was able to implement the of the control but the problem is making the control stay open until the mouse is hovered out of the control region.
The code is :
Private Sub btnCourseRegistration_MouseHover(sender As Object, e As EventArgs) Handles btnCourseRegistration.MouseHover
TabControlSubMenu.Visible = True
TabControlSubMenu.SelectedTab = TabPageCourseRegistrationSubMenu
End Sub
Private Sub btnCourseRegistration_MouseLeave(sender As Object, e As EventArgs) Handles btnCourseRegistration.MouseLeave
If TabControlSubMenu.Focused = False Then
TabControlSubMenu.Visible = False
Else
TabControlSubMenu.Visible = True
End If
End Sub
Private Sub TabControlSubMenu_MouseLeave(sender As Object, e As EventArgs) Handles TabControlSubMenu.MouseLeave
TabControlSubMenu.Visible = False
End Sub.

make label update on file directory change (visual basic)

When I use an OpenFileDialog, and select a file and click open etc, etc...
I want a label on the same form to automatically update with the directory path. At the moment I have this working, However the label updates on click, not automatically on the directory change.
CODE:
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
Label4.Text = OpenFileDialog2.FileName
End Sub
Cna I change the "Label4_Click" to something else for an auto update?
How are you displaying the OpenFileDialog? You need to update the Label from there!...
Something like:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If OpenFileDialog2.ShowDialog = Windows.Forms.DialogResult.OK Then
Label4.Text = OpenFileDialog2.FileName
End If
End Sub

Where to add code?

I am just starting out with windows forms and I am making a button with a mouseover image change (I know I should probably wait with this untill later) and I found this webpage that describes it.
How to change button background image on mouseOver?
and my current code looks like this
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
But I am not sure about where to add the code that is in the link. It gives me error anywhere I put it.

visual basic 2010 copy paste subroutine

I am trying to write 2 simple subroutines in VB 2010 that could be used with toolstripbutton contorls for multiple textboxes in a form. I know simple copy paste could be done using the textbox1.Copy() and TextBox1.Paste() methodes. What i am trying to do is write a common subroutine which could be used on any textboxes in the form not just one particular textbox.
My codes are below, I know there are errors in it, just wondering how it could be achieved. Any help would be highly appreciated. Thanks.
Public Class Form1
Private Sub copytext()
Dim txt As Control
If TypeOf txt Is TextBox Then
Clipboard.Clear()
Clipboard.SetText(txt.SelectedText)
End If
End Sub
Private Sub pastetext()
Dim txt As Control
If TypeOf txt Is TextBox Then
txt.Text = Clipboard.GetText
End If
End Sub
Private Sub mnuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCopy.Click
Call copytext()
End Sub
Private Sub mnuPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPaste.Click
Call pastetext()
End Sub
End Class

Resources