VB .net Clickonce - check for update but dont update - vb.net

ok so ive got an updating program via clickonce, I want it to notify the user there is an update but don't actually update the program until an admin logs on and requests the update to go ahead.
I'm checking for updates like this via code
If My.Application.IsNetworkDeployed() Then
If My.Application.Deployment.CheckForUpdate() Then
MsgBox("Updates are available", vbInformation, "Updates available")
Note I haven't called the
My.Application.Deployment.Update()
to actually update.
When my application checks for updates it displays ok, but when no one does anything else when it is shut down again and then started up - it seems to revert back to automatically downloading the update on program startup. I have update automatically turned off in the project properties
I tried not checking for updates and the program starts and doesn't update so I'm thinking that just the act of checking and finding an update automatically sets the program to download it next time its started. which id rather it didn't
has anyone come across this issue before?
thanks

Modify this code. It is with an "updating" action but you'll be able to change this
Imports System.Deployment.Application
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim updateCheck = ApplicationDeployment.CurrentDeployment
Dim info = updateCheck.CheckForDetailedUpdate()
If (info.UpdateAvailable) Then
MsgBox("Update wird geladen.")
updateCheck.Update()
MessageBox.Show("The application has been upgraded, and will now restart.")
Application.Restart()
End If
Catch : End Try
Form1.Show()
Me.Close()
End Sub

Do you by any chance have these options selected??
If you're handling the updates programmatically, you need to untick the "The application should check for updates" box.
Doing this will grey-out the "After" and "Before" radio buttons below it.

Related

Adding data in vb.net application does not change ms access database file

I am creating a library software. I have connected an access database with my vb application. In "Add book form", whenever i add a book in there, it shows in datagridview below it but as i restart the application, i find that data is gone as saving data through form is not affecting my database file.
Here is the code:
Public Class addForm
Private Sub BooksBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
Me.Validate()
Me.BooksBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DataDataSet)
End Sub
Private Sub BooksBindingNavigatorSaveItem_Click_1(sender As Object, e As EventArgs) Handles BooksBindingNavigatorSaveItem.Click
Me.Validate()
Me.BooksBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DataDataSet)
End Sub
Private Sub addForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DataDataSet.Books' table. You can move, or remove it, as needed.
Me.BooksTableAdapter.Fill(Me.DataDataSet.Books)
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Try
BooksBindingSource.EndEdit()
BooksTableAdapter.Update(Me.DataDataSet.Books)
MessageBox.Show("Book added successfully")
Catch ex As Exception
MessageBox.Show("Error")
End Try
End Sub
End Class
Name of my table is "Books". And also it shows "Book added successfully" after clicking on add btn.
Here is a screenshot of the folder structure of one of my projects that uses an access db:
Circled in BLUE is the accessdb that I added to the project. This is the DB file I see in Solution Explorer
Circled in RED is a copy of the blue DB; it is copied to the bin\Debug folder every time I run a build (start the app)
The program runs from the bin\Debug folder (or release if you're using that build configuration) and it saves its data in the RED database
This means every time my program saves a change to the DB, the build process will overwrite the red DB with a fresh copy of the blue DB, next time the build process runs
So, every time I start the app, previous modified database is overwritten with a blank one
I can change this behavior if I click on the blue DB in solution explorer:
Copy always - always overwrites red db with blue db
Copy if newer - copy means db have same date, then your program edits red DB so it is newer, build process doesn't overwrite it.. If you make a change to the blue DB (add a table etc) then blue DB is newer, build will overwrite red db. This is a good setting to use
Copy never - you must manually copy the db
VS probably gave some info about this when you first added the DB, but the dialog it shows up is wordy and boring, so most people don't read it or don't really get what it's talking about even if they do read it:
Clicking Yes eventually causes you to ask a question like this on SO :) - no bad thing, but I do wish MS had made "Copy if Newer" the default..
Other notes about your code:
The topmost Sub BooksBindingNavigatorSaveItem_Click) is redundant - remove it
The btnAdd_Click method is nearly an identical re-statement of BooksBindingNavigatorSaveItem_Click_1 and is hence probably redundant - it should be removed. If you have two buttons intended to save data, put the save code into a sub and call it from both button click handlers; don't repeat yourself

How to delete a record in VB.net with Access database?

I am a beginner so I followed a tutorial on YouTube and made a program in VB.net using Windows Form that connects to an Access database. The program works, it can move to Previous record, Next record, Add new record and Save. However, the Delete button doesn't work.
I have tried searching for solutions and it was mentioned that I needed to have a Primary Key in the Access database or it wouldn't create a Delete command. So, I set a Primary Key then ran the program but Delete still doesn't work.
I've read that I need to configure the TableAdapter Configuration Wizard but they didn't specify on what exactly I should do. I tried messing around a bit and when I clicked on the Properties of the Table Adapter, I now see a DeleteCommand. However, I'm not sure of what to do with it or how to make it work.
This is what the delete button does
Private Sub DeleteBtn_Click(sender As Object, e As EventArgs) Handles DeleteBtn.Click
PatientRecordsBindingSource.RemoveCurrent()
End Sub
And this is what the save button does:
Private Sub SaveBtn_Click(sender As Object, e As EventArgs) Handles SaveBtn.Click
On Error GoTo SaveErr
PatientRecordsBindingSource.EndEdit()
PatientRecordsTableAdapter.Update(DatabaseDataSet.PatientRecords)
MessageBox.Show("Ok")
SaveErr:
Exit Sub
So, I run the program and I can add and save new records in the table. But when I select a record from the table and then click the Delete button, it only deletes the record on the program. When I check the Access file, the supposedly deleted record is still there. But then I ran the program again and the record I tried to delete is back in the table, like nothing happened.
EDIT: I created a new Access Database file, made sure I assigned a Primary Key then tried it on a new form. It worked, but I am still wondering if I can still fix my problem with the old form.

If statement makes debugger skip backwards

I have a Visual Studio 2015 Windows Forms program with a menu form and several others. The code for the menu button in question looks like this:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Visible = False
Form1.Show()
End Sub
When this button is pressed, Form 1 is loaded. Within the Form 1 load event is the following For loop:
For i As Integer = 1 To 10
If x_DataTable.Rows(0)(i.ToString()) <> "" Then
Me.Controls(("txt" & (i)).ToString()).Text = x_DataTable.Rows(0)(i.ToString())
Dim s As String = Me.Controls(("txt" & (i)).ToString()).Text.Trim()
If Convert.ToInt32(s.Substring(s.Length - 2)) < (m_DataTable.Rows(0)("Limit")) Then
Me.Controls(("txt" & (i)).ToString()).BackColor = Color.IndianRed
End If
End If
Next
Every time that the debugger hits the line that starts with "If Convert.ToInt32", it exits the for loop and the load event sub, and skips backwards to the Form1.Show() statement in the menu code above. Any idea what might be causing this or how to make it execute the code normally?
The Form.Load event has some odd exception handling behavior on x64 systems compared to x86 when a debugger is attached. When an exception is unhandled in a x86 process running on an x64 version of Windows the function is basically aborted, and the exception is eaten by the wow64 sub-system. Execution resumes at the last .net code on the stack before Load was called.
See this answer for a very thorough explanation.
Please Check Convert.ToInt32(s.Substring(s.Length - 2)) , (m_DataTable.Rows(0) ("Limit")) are valid Integers
Ok, I think I figured it out. The "Limit" column at row 0 was null, so it was not able to execute that line. Still not sure why it didn't show any error messages and just skipped backwards though.
Sounds like the assemblies and the source code are out of sync. Have you changed the config (Release|Debug) or maybe not built, or build to the wrong location?

Winforms RadTextBox control validating event triggered twice

I am doing a database validation on the TextBox validating event. I am also using the e.Cancel = True if the data is invalid. The problem is that the validating event is triggered twice ultimately causing the SQL also to run twice, and I don't want that to happen (coz sometime the query is resource intensive).
Steps:
Drag & drop a RadTextBox & a RadLabel to the Form.
For the RadTextBox validating event use the below code.
Run the application, focus the RadTextBox & then click on the label. Then if you check the output window of visual studio you will notice that the console has logged that the validating event was actually triggered twice. (The event runs twice only when I try to click a RadButton or a RadLabel)
I noticed this bug when I was checking my queries in SQL Server Profiler & the query gets executed twice, which is unnecessary. I also checked with actual wincontrols & this issue doesn't exist in them.
How do I fix this issue ?
Here a sample code to replicate the behavior
Private Sub RadTextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles RadTextBox1.Validating
Console.WriteLine("VALIDATING EVENT TRIGGERED")
e.Cancel = True
End Sub
It seems as a known issue with RadTextBox: issue link
Perhaps you can try RadTextBoxControl for your needs?

Lost Focus problems

I use the LostFocus Event in vb.net to check the validity of a field for the name.
After this field a have another one which is the for the password validity, and i'm handilg the same event in order to check the password.
My problem comes when i run the (name) lost focus, runs the code inside the sub and after that automatically goes to the password_lostfocus which brings me alot of troubles.
That happens even i use the error provider which works fine and bring to me the error with the red flashing.After that i put the command (name_textbox.focus), which logically has to bring the control in the name_textbox.. But NO.. the control goes to the Password_textbox sub automatically.
Please see my sub
Private Sub UsernameTextBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles UsernameTextBox.LostFocus
Select Case DB_Access.IfExistUser(UsernameTextBox.Text, sender, e)
Case True
PasswordTextBox.Focus()
Case False
ErrorProvider1.SetError(UsernameTextBox, "Ο χρήστης ΔΕΝ υπάρχει παρακαλώ καλέστε τον Administrator")
Beep()
UsernameTextBox.Text = ""
UsernameTextBox.Focus()
End Select
End Sub
Please if anyone have seen this issue and face it, assist me.
Excuse me for some Greek characters they are meaningless, they are comments
Well finally i found that.
In order to handle the Login Form as it give it from visual studio 2010 you need to do it in only one sub (Lost Focus) and that is only the password_LostFocus.
I believe the particular form is meant to be like that.
Any way i solve the issue and if anybody needs assistance on that just "asc a question"