How can i add into access database from vb.net - database

Am still learning VB and database but I have a little problem. My codes works but when I
try to look into the database I don't find all what are been saved, how do I rectify it? and also the edit and delete. thanks
Here is my code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ItemsDataSet.Items' table. You can move, or remove it, as needed.
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet.Items)
'TODO: This line of code loads data into the 'ItemsDataSet.Items' table. You can move, or remove it, as needed.
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet.Items)
'TODO: This line of code loads data into the 'ItemsDataSet.Items' table. You can move, or remove it, as needed.
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet.Items)
End Sub
Private Sub ItemsDataSetBindingSource_CurrentChanged(sender As Object, e As EventArgs)
End Sub
Private Sub btnedit_Click(sender As Object, e As EventArgs) Handles btnedit.Click
ItemsBindingSource.EndEdit()
ItemsTableAdapter.Update(ItemsDataSet.Items)
MsgBox("Saved")
End Sub
Private Sub btadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
ItemsBindingSource.AddNew()
MsgBox("Added Successfully")
End Sub
Private Sub btndelete_Click(sender As Object, e As EventArgs) Handles btndelete.Click
ItemsBindingSource.RemoveCurrent()
MsgBox("Item Deleted")
End Sub
Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
Close()
End Sub
Private Sub btnprevious_Click(sender As Object, e As EventArgs) Handles btnprevious.Click
ItemsBindingSource.MovePrevious()
End Sub
Private Sub btnnext_Click(sender As Object, e As EventArgs) Handles btnnext.Click
ItemsBindingSource.MoveNext()
End Sub
End Class

You probably have your MDB (ACCDB) file included in your project files.
If you check the properties associated with this project file you will find one named Copy to Output Directory. Set this to Copy Always.
Also your connection string contains the shortcut Data Source = "|DataDirectory|\yourdb.mdb"
If this scenario is correct, then you start your application and the MDB / ACCDB file is copied from the original location to the BIN\DEBUG directory.
You insert your data there without error. When you stop the debug session to fix errors or other problems you restart your application and the fresh copy (but empty) of your db is copied again in the output directory.
To fix this, set the property to Copy Never or change your connection string to point to a fixed location.

Related

Calling method from button click does not have compatible signature

I'm getting a "...does not have a signature compatible with delegate..." message when trying to pass a parameter to a method. Can someone advise me on what I'm doing wrong?
Private Sub btnSubmit_Click(sender As Object, e As RoutedEventArgs) Handles btnSubmit.Click
Step6Click("btnSubmit")
End Sub
Private Sub Step6Click(whereFrom As String)
Initially, no error is flagged but when the application is built, that's when the error occurs.
I changed ("btnSubmit") to ("xxx") thinking there was some conflict with passing "btnSubmit" when there was a button named the same. Still get the error.
If I take out the parameter all together, then no error occurs, but I need to know in Step6Click where the call came from.
I can bypass the error by creating a property or variable called "whereFrom". However I'd like to understand why this is an error.
Complete error message:
Error 33 Method 'Private Sub Step6Click(whereFrom As String)' does not have a signature compatible with delegate
'Delegate Sub RoutedEventHandler(sender As Object, e As System.Windows.RoutedEventArgs)'.
Thanks.
If Step6Click is an event handler that you are trying to hook up to the Click event of a Button in your XAML markup it should have the following signature or no parameters at all:
Private Sub Step6Click(sender As Object, e As RoutedEventArgs)
End Sub
You could create another method that you call from both your event handlers, i.e. just create another method with a different name, e.g.:
Private Sub btnSubmit_Click(sender As Object, e As RoutedEventArgs) Handles btnSubmit.Click
Step6ClickMethod("btnSubmit")
End Sub
Private Sub Step6Click(sender As Object, e As RoutedEventArgs)
Step6ClickMethod("btnSubmit")
End Sub
Private Sub Step6ClickMethod(ByVal whereFrom As String)
End Sub

VB.net deleting a record but stills shows in database access file

I have created a database file in MS access and linked to vb.net form. When i delete a record at run time it shows deleted in user interface but when i checked the Database file its stills in DB file what should i do ?
I have used this function
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
StudentData1BindingSource.RemoveCurrent()
End Sub
Try saving after you remove the record. Should look something like this:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
StudentData1BindingSource.RemoveCurrent()
Me.Validate()
Me.StudentData1BindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.StudentData1DataSet)
End Sub

Problems updating the database

I have attached code for reference. I am trying to create database for my project details. I have currently 2 forms:
main form
project detail form
Main form used to switch various forms
Project detail forms are meant for add / edit / load project details
My main form in visual basic look like this.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Bt_Project_Details_Click(sender As Object, e As EventArgs) Handles Bt_Project_Details.Click
Me.Hide()
Project_Details_Form.Show()
End Sub
End Class
My project detail form look like this.
Public Class Project_Details_Form
Private Sub Project_Details_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Project_Data_Set.Project_Data_Table' table. You can move, or remove it, as needed.
Me.Project_Data_TableTableAdapter.Fill(Me.Project_Data_Set.Project_Data_Table)
End Sub
Private Sub Bt_Load_Project_Click(sender As Object, e As EventArgs) Handles Bt_Load_Project.Click
End Sub
Private Sub Bt_Cancel_Click(sender As Object, e As EventArgs) Handles Bt_Cancel.Click
Me.Hide()
Form1.Show()
End Sub
Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
Project_Data_TableBindingSource.AddNew()
End Sub
Private Sub Project_Data_TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Project_Data_TableBindingNavigatorSaveItem.Click
Me.Validate()
Me.Project_Data_TableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Project_Data_Set)
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
Project_Data_TableBindingSource.RemoveCurrent()
End Sub
Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs)
Try
Me.Project_Data_TableTableAdapter.FillBy(Me.Project_Data_Set.Project_Data_Table)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Now I am facing a few problems:
Whenever I run the program, try to enter first entry data being saved but with empty value. The data enter next time being stored properly. How can make my first entry visible?
In below code:
Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
Project_Data_TableBindingSource.AddNew()
End Sub
I am using AddNew(). This working fine, but problem is even I don't enter data like date, name kept empty, data recorded in their position is store empty only. I would like to say if any of project data set is empty give error message (since it mandatory for user to enter those data)
Is there any other method where i can assign value individually .
Like my Project database contain project name, customer name etc. if i say new button pressed clear all field. Once form filled individual value being record once save button pressed
Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
Project_Data_TableBindingSource.AddNew()
End Sub

Update a MS Access database in VB.NET

This is my first post on stackoverflow so please hang with me. I am attempting to update an access database using VB.NET. Using the following series of videos (starting with this one), we have been able to properly use our form to save new data into the access database.
https://www.youtube.com/results?search_query=vb.net+ms+access+database+tutorial+1+%23+add+new+remove+save+data+in+database+using+vb.net
However, when we start up the form again after opening up access to make sure the updates have occurred (which they always do), none of our changes are there. And when we open up access again the changes we made that showed up in the access database are gone, and the access database goes back to its original state (the state it was when we linked it to visual studio in the first place).
Below is the code we have so far, we appreciate any help you can give us!
Thanks.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Sheet1BindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Sheet1BindingNavigatorSaveItem.Click
Me.Validate()
Me.Sheet1BindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(MIS275_Small_BusinessDataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MIS275_Small_BusinessDataSet.Sheet1' table. You can move, or remove it, as needed.
Timer1.Start()
Me.Sheet1TableAdapter.Fill(MIS275_Small_BusinessDataSet.Sheet1)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Sheet1BindingSource.AddNew()
End Sub
Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click
Try
Sheet1BindingSource.EndEdit()
Sheet1TableAdapter.Update(MIS275_Small_BusinessDataSet.Sheet1)
MessageBox.Show("Data Saved")
Catch ex As Exception
MessageBox.Show("Error")
End Try
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim count As Integer
count = Sheet1BindingSource.Count
End Sub
End Class

getting a color from a database entry and applying it to a label background

I am having trouble getting the color the user picks and saving it into a database so that when they reload the program it will automatically apply to the labels background.
I have this to let the user chose the color
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If ColorDialog1.ShowDialog = DialogResult.OK Then
Quiz.LTitle.BackColor = ColorDialog1.Color
End If
End Sub
Then i have a button to save it with the code so far as
Private Sub BTitleSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTitleSave.Click
BackGroundWork.Title_SettingsBindingSource.AddNew()
BackGroundWork.Title_BColorTextBox.Text = Quiz.LTitle.BackColor.ToArgb
BackGroundWork.Title_SettingsBindingSource.EndEdit()
BackGroundWork.Title_SettingsTableAdapter.Update(BackGroundWork.QuizSettingsDataSet)
End Sub
BackGroundWork is a form where i have all my databases running
Quiz is the form that everyone will see.
any help would be appreciated
You can try ColorInHex ...
Private Sub BTitleSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTitleSave.Click
BackGroundWork.Title_SettingsBindingSource.AddNew()
BackGroundWork.Title_BColorTextBox.Text = Quiz.LTitle.BackColor.ToArgb.ToString("X")
BackGroundWork.Title_SettingsBindingSource.EndEdit()
BackGroundWork.Title_SettingsTableAdapter.Update(BackGroundWork.QuizSettingsDataSet)
End Sub
When you called it ..
Dim sColor as String = ... -> this retrieve from database
Quiz.LTitle.BackColor = System.Drawing.ColorTranslator.FromHtml(sColor)
Hope this works for you !

Resources