Access database connecting to VS but no data showing and runtime error - vb.net

Trying to use an access database with Visual studio 15. After failure I found a number of tutorials and followed them with a new project and new database.
The database is connecting but the data inside the database won't display (although no error) and even using the built in save function in VB results in a run time error.
If anyone can point me in the right direction I'd be grateful. Code below.
Public Class Form1
Private Sub CustomersBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles CustomersBindingNavigatorSaveItem.Click
Me.Validate()
Me.CustomersBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.CustomersDataSet) 'Error is here****
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CustomersDataSet.Customers' table. You can move, or remove it, as needed.
Me.CustomersTableAdapter.Fill(Me.CustomersDataSet.Customers)
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
End Sub
Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
End Sub
End Class
The error message I get is An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Unspecified error.

Here is a video that I made a while ago that should be able to help you, If you have any questions about it, i can definitely help you out.
https://www.youtube.com/watch?v=vvzY0LsAUNE
Also do you definitely need to use Access? I would recommend using an SQL database because when you publish your program, the end user may have to have a link to your access database in the same spot as yours, which can be a pain.
Nevertheless here is a video i also made regarding setting up an SQL database via Visual Studio.
https://www.youtube.com/watch?v=NLs44hxV514
If you have any issue, leave a comment and i will be happy to help you out :)
Keep In Mind
Don't forget that you need to also have a Number/unique word/or something a like in the Primary key column even if you haven't added any details to the database. eg Name and so on. If not your program may crash, so you could use the Try statement to fix this issue if the Primary Key column is left empty.

Related

How to save, edit, and create new record in Access Query with VB.NET

I have a task from school to make a simple program with VB.NET and currently having an issue now. I've connected my MS Access Query (Query, not Table) with my form in VS2015. The program run smoothly, but when I want to update the data, this error message came up
TableAdapterManager contains no connection information. Set each TableAdapterManager TableAdapter property to a valid TableAdapter instance.
I used this following code to update the database
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.Validate()
Me.JoblistBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Joblist)
End Sub
I need this program to run as late as Thursday.
Does anyone know how to fix this problem? Thanks before.

How do i update different table from the same access database using visual basic .net

I added my Enrollment system access Database, into my Enrollment System vb.net form, as a data source. The Database has 2 tables in it, the accountTable and studentEnrollmentInformation. I dragged The accountTable's details and data grid view into my form designer. The following code automatically appeared in the code designer:
Private Sub AccountTableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
Me.Validate()
Me.AccountTableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.EnrollmentSystemDataBaseDataSet)
End Sub
Private Sub enrollmentSystem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AccountTableTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.accountTable)
End Sub
The following code works for updating the accounTableDataGridView but it does not work for studentEnrollmentInformationDataGridView so i manually created one
for studentEnrollmentInformation.
Function updateStudent()
Me.Validate()
Me.StudentEnrollmentInformationBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.EnrollmentSystemDataBaseDataSet)
Me.StudentEnrollmentInformationTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.studentEnrollmentInformation)
End Function
This is the function that contains the update code, that i manually created for updating the studentEnrollmentDataGridView. Adding new Row works fine but when i try to update studentEnrollmentDataGridView the texts in the table disappears and does not update/save. I also had function for updating the accountTableDataGridView which works fine.
Function update() 'THIS FUNCTION CONTAINS PRE-MADE CODE TO MAKE UPDATING SHORTER IN WRITING CODE.
Me.Validate()
Me.AccountTableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.EnrollmentSystemDataBaseDataSet)
Me.AccountTableTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.accountTable)
End Function
My Question is how do i update multiple Tables in my system? Updating the other table works fine but the other is not.
In the original auto-generated code, this is the line that retrieves the data in the first place:
Private Sub enrollmentSystem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AccountTableTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.accountTable)
End Sub
When the form loads, the Account data is retrieved into a DataTable that is already bound. If you want to retrieve Student Enrollment data too, do it in the same place:
Private Sub enrollmentSystem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AccountTableTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.accountTable)
Me.StudentEnrollmentInformationTableAdapter.Fill(Me.EnrollmentSystemDataBaseDataSet.studentEnrollmentInformation)
End Sub
Now you're populating both bound DataTables when the form loads. When it comes to saving, you do the same thing, i.e. add the code to save the changes to the other DataTable where you already have the code to save the first:
Private Sub AccountTableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
Me.Validate()
Me.AccountTableBindingSource.EndEdit()
Me.StudentEnrollmentInformationBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.EnrollmentSystemDataBaseDataSet)
End Sub
You don't need any code to specifically save the changes from the DataTable because the whole point of UpdateAll is that it updates all DataTables in the DataSet.
As is always the case, if it doesn't seem to be working as you expect then you debug it. In that case, that would mean setting a breakpoint on the UpdateAll line and examining the exact state of the DataSet before and after the call, as well as possibly examing the sate of the database too.

Validating License Key on separate form?

I have an application which has a license key function.
The user gets their license key, then type it into the TextBox where the license key is supposed to go, and if the license key is valid, they get taken to the main form, where all of the features are.
Now, to make my program more secure, I need to be able to check that the user has definitely typed in their license key, and they haven't done something like delete (by decompiling) the license key form so they can gain access to the main form where all of the features are.
Note: My license keys are stored on a server.
How would I check that the user has definitely typed in the license key?
Below is the code.
AddLicense.vb:
Imports SKM.V3
Imports SKM.V3.Models
Imports SKM.V3.Methods
Public Class AddLicense
Private p_oRandom As Random
Private Const INTERVAL_MIN_SEC As Integer = 4
Private Const INTERVAL_MAX_SEC As Integer = 25
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If BunifuProgressBar1.Value = 50 Then
Label3.Show()
Label2.Hide()
End If
BunifuProgressBar1.Value += 1
If BunifuProgressBar1.Value = BunifuProgressBar1.MaximumValue Then
BunifuProgressBar1.Hide()
Label3.Hide()
Label2.Hide()
Timer1.Stop()
BunifuMaterialTextbox1.Show()
BunifuThinButton21.Show()
Label4.Show()
LinkLabel1.Show()
BunifuThinButton22.Show()
End If
Timer1.Interval = p_oRandom.Next(INTERVAL_MIN_SEC, INTERVAL_MAX_SEC) * 3
End Sub
Private Sub BunifuImageButton1_Click(sender As Object, e As EventArgs) Handles BunifuImageButton1.Click
Me.Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
p_oRandom = New Random
End Sub
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Try
Process.Start("https://selly.gg")
Catch ex As Exception
End Try
End Sub
Sub Nolicense()
BunifuThinButton21.Enabled = False
End Sub
Private Sub BunifuThinButton21_Click_1(sender As Object, e As EventArgs) Handles BunifuThinButton21.Click
Dim token = "WyIxMDM2IiwiZ082d2dnS0FmTkRuTXNPcGhlSkllVEx6ckFWMFhhSzlMM3Rvc01xUSJd"
Dim key = BunifuMaterialTextbox1.Text.Replace(" ", "")
Dim license = New LicenseKey() With
{
.ProductId = 3888,
.Key = key
}
If license.Refresh(token, True) Then
' we are able to auto complete missing key info
Me.BunifuThinButton21.Enabled = license.HasFeature(1).IsValid() ' either we have feature1 or not.
MsgBox("License is valid! Thanks for purchasing.")
Me.Hide()
Sploitbase.Show()
If license.HasFeature(4).HasNotExpired().IsValid() Then
Me.Hide()
Sploitbase.Show()
ElseIf license.HasNotFeature(4).IsValid() Then
Else
MsgBox("Your license has expired and cannot be used.")
Nolicense()
End If
license.SaveToFile()
Else
' something went wrong.
MsgBox("Unable to access the license server or the key is wrong.")
End If
Me.Close()
End Sub
Private Sub BunifuThinButton22_Click(sender As Object, e As EventArgs) Handles BunifuThinButton22.Click
End Sub
End Class
Sploitbase.vb - the main form:
Imports SKM.V3
Public Class Sploitbase
Private Sub Sploitbase_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Public Sub NoLicense()
End Sub
Private Sub TabPage1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs)
Try
Process.Start("https://selly.gg")
Catch ex As Exception
End Try
End Sub
End Class
I believe what you want is to stop users from decompiling your program and removing the license key form entirely...
Unfortunately, it's impossible to stop that, as long as a program can be run on an ordinary computer, it can be decompiled, otherwise, it would be impossible for the processor to process it.
This means, that it would be possible to remove the relevant instructions for that, and C# and VB is easy to decompile - tools like dotPeek get valid source code (it won't be exactly the same as the original, but still readable and runs like the original) just with a click.
Keep in mind that even proper commercial programs made by whole companies have this problem.
So, what could you possibly "do"? Well, I only really have two suggestions... but they won't work too well.
One only makes it harder and the other one requires access to the internet all the time.
Obfuscation
Obfuscation essentially makes the code harder to read after decompiling, however, it won't stop people from deleting the form, it will just make it slightly harder.
I posted it as an option because it will make the code very confusing when recompiling and it might be helpful to "protect" it a bit more. However, just remember this: "It's a weak layer of defence for a weak attacker."
An obfuscator you could use is Eazfuscator.NET, that webpage I sent also has a description of essentially what it does and how to use it - it may be worth taking a look at.
Online Servers
This one requires a connection to the internet... but, it's the only other option you have at all - it's either this or... able-to-get-rid-of-product-key.
Essentially, in this idea, you make a server do all the work that the application has to do and then return the result of it.
Imagine the user's computer is a server. Their "server" runs the code, and so the code is on their "server" (otherwise it has nothing to run) and everything is processed on their server. Now, if you run it on your server, all the code is on your server and your server only returns the result, meaning, they can't get at the process that provides that result.
In the end, this would mean that the application physically would not be able to do anything without a license key, since the only way it can get its data processed is via the server, and the server won't process the data without a product key.
The only downside to this is that you must have an internet connection and if the internet connection is slow - the program will be slow.
Since you want to know how to do this in vb.net taking a look at ASP.NET may help, but it's really designed to make a full-website - not to just process a few tasks.
I can leave it up to you how you would want to approach this task but here's one way of doing this:
The code below will make a "request" to a certain URL and then get the result back - with this, you could make it so when it goes to that URL the server processes the data given (including the product key) and returns back a result.
Dim request As System.Net.HttpWebRequest
Dim response As System.Net.HttpWebResponse
request = System.Net.HttpWebRequest.Create("https://URLHERE")
response = askforupdate.GetResponse
Dim result As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream)
result now contains a String - but, keep in mind that you can use this for practically anything - even images! (Images are just New Bitmap(response.GetResponseStream))
You can pass data to the server via a Query String, for example:
my.website/processSomething?license=AAAAAAAA&sizeInput=241&somethingElse=asagsag
But, really, it's up to you how you do that.
I'm sorry I couldn't give you an exact solution, but, there really isn't one. You're going to end up sacrificing something either way.
Hopefully, this was at least helpful and helped you understand that it's really not possible to prevent people hacking your software without losing something.

Save/Load full form

I am writing a program for a friend in my free time to use to document students for physical therapy and occupational therapy. I'm using visual basic and have created a basic form so far, but realized I'm not sure how to save/load the information that will be input.
This is what the form looks like so far (basic I know)
Form
I do not have access to sql or ms access at the moment so I'm hoping to be able to save all the information to a txt document or xml file and be able to read and update it at a future time. Eventually I will have multiple forms all associated with one student and would like to save them all together.
Any help would be GREATLY appreciated.
You can use this method, it will work perfect but the data will be stored in a xml file and it's editable :
First you go to your project properties :
Then you go the the settings tab :
And there you add all the variables that you need to store data in :
So to save the data you can use the Form_Closing event :
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
My.Settings.StudentName = StudentNameTextBox.Text
'.......
'....
'And you do that for all the information that you need to store.
End Sub
To Load the data when the form loads, just revers the storing way :
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
StudentNameTextBox.Text = My.Settings.StudentName
'.......
'....
'And you do that for all the information that you need to load.
End Sub
Hope that will be useful to you :)

VB.NET/Access DataGridView not displaying table contents

I'm attempting to display an Access Database table in a DataGridView on the most simple form you could make. However, when I start the application I don't see any of the table data. See below.
I'm happy to update with any additional information needed.
VB:
Option Explicit On
Option Strict On
Option Infer Off
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 'MOKANDataSet.SalaryHistory' table. You can move, or remove it, as needed.
Me.SalaryHistoryTableAdapter.Fill(Me.MOKANDataSet.SalaryHistory)
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Here is the application at runtime.
Overview of project in Visual Studio
I was curious and went directly to the executable in the bin folder. Upon execution, I got "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine. I'm using Win 7 64 Bit, but the Microsoft Office suite I have is 32-bit. I got the 32-bit AccessDatabase Engine referenced here