How to keep textbox data when copying a form to another computer? - vb.net

I have a form with two textboxes and two buttons, I want the data in the two text boxes to be saved when the computer shuts down or when the form containing the two textboxes is copied to another computer.
Savedata1
Public Class Form1
Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
My.Settings.SaveTitle = TextBox1.Text
My.Settings.SaveBody = TextBox2.Text
MsgBox("Saved textbox data")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = My.Settings.SaveTitle
TextBox2.Text = My.Settings.SaveBody
End Sub
Private Sub EndButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EndButton.Click
Me.Close()
End Sub
End Class
With the above code, I can only save data when the computer shuts down, but when copying the form to another computer the data in the textbox is not saved.
Can you show me how to keep textbox data when copying form to another computer?
Thank you for your help.

Are you wanting the data from the TextBoxes to be shared among all copies of the application? Like if you change the values on one computer, they update on the others?
Or, do you want the data to be persistent on an application copy instance? Like if I have a copy and change the values, the person I share the application with shares my values?
If you want the data to be consistent across all instances, use a webserver to store the values (either in a data store or as a simple XML file), and have each instance download the values on startup, or at regular intervals.
If the values are to be set by you, the developer, you could simply recompile the application with the new values and let the ClickOnce deployment system handle all the client updates for you.
If you want the values set on a copy per copy basis, you will have to include a file containing the values with the application, so each new user gets the application and the settings file as part of the package.

Related

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.

Accessing Windows Security through Visual Basic

I've created a code that copies the folder contents from PC1(pc for user) to PC2(pc for server). I used Active Directory to create accounts for the access of PC2's server
I have the ff code to transfer from PC1 to PC2:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Computer.FileSystem.CopyDirectory("C:\Users\Bounty Hounds\Desktop\1", "\\WIN-2I9JBRPFMO7\UserFiles\joshua824\Desktop\joshua824", True)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
My.Computer.FileSystem.CopyDirectory("\\WIN-2I9JBRPFMO7\UserFiles\joshua824\Desktop\joshua824", "C:\Users\Bounty Hounds\Desktop\1", True)
End Sub
End Class
This only works if you pass the server's login information that only seems to show when I try to manually enter the address of the server
I found two ways to approach this problem
First
Create a login form
Second form would tell Windows Security via vb code that my username and password are what I inputted on the login form
Second
Create a code that will show Windows Security automatically when running my visual basic program
However i'm struggling on how do I tell Windows Security about my login info and at the same time I don't know how do I manually show Windows Security

vb.net data not saved sql compact database when after closing the application

I did small application, to save insert data to table....
The application is not saving the data after the application close..
Can any one tell me what is the wrong in the code.
Imports System.Data
Imports System.Data.SqlServerCe
Public Class Form1
Public connstring As New String("Data Source=|DataDirectory|\test_db.sdf")
Public sqlconn As New SqlCeConnection(connstring)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim name As New String("jaifar")
Dim myCommand As New SqlCeCommand("Insert Into table1 (id) Values('" + name + "')", sqlconn)
If sqlconn.State = Data.ConnectionState.Closed Then sqlconn.Open()
myCommand.ExecuteNonQuery()
Me.Table1TableAdapter.Fill(Me.Test_dbDataSet1.table1)
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
sqlconn.Close()
sqlconn = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Test_dbDataSet1.table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Test_dbDataSet1.table1)
End Sub
End Class
There are few ways to work around this:
If you select local database file in the Solution Explorer window, you will see a property called ‘Copy to Output’ in the Properties window. By default it is set to ‘Copy Always’ which means that on each build, the data files in the project folder will be copied to the output folder overwriting the existing data files if any. You can set this property to Copy Never and then manually put a copy of the data file in the output folder. This way, on subsequent builds, the project system will leave the datafile in the output folder and not try to overwrite it with the one from the project. The downside is that you still have two copies so after you modify the database file using the app, if you want to work on those changes in the project, you need to copy it to the project manually and vise-versa.
You can leave the data file outside the project and create a connection to it in Database Explorer. When the IDE asks you to bring the file into the project, just say no. This way, both the design-time and the run-time will be using the same data file but the downside is that the path in the connection string will be hard coded and therefore it’ll be harder to share the project and deploy the app. Before deploying the app, just make sure to replace the full path in the settings with a relative path.
Source: https://arnulfo.wordpress.com/2007/07/21/visual-studio-and-local-databases/
after
myCommand.ExecuteNonQuery()
then write
sqlconn.Close()
Cause, when you have write execute, better close it.
You must know that saving to dataset with database is not same.. Dataset is temporaly in your program, mean still not get change in database.
and, where is our + name + value??
Like,
mycommand.addwithvalue("name", the value place)

VB 2008 Displaying data in ListBox then Transfer the data to another ListBox

In VB 2008 I created 2 list box. The first list box is to load all the data in my database in a specific row, the other list box is when I double click on the data/item on the first list box the specific data/item need to be transfer to the second list box.
I manage to transfer the data, but the output it gave was wrong. Instead of the actual name of the given data/item the output it gave was System.Data.DataRowView. I tried using .ToString() but nothing happens. I used the drag and drop method for the data adapter connection and the database I'm using is MySQL. I use the "Use data bound items" on list box 1.
You should do it like this,
Private Sub ListBox1_DoubleClick(sender As Object, e As EventArgs) _
Handles ListBox1.DoubleClick
' checks if the item is empty
If ListBox1.SelectedItem.ToString.Length <> 0 Then
' adds on listbox 2
ListBox2.Items.Add(ListBox1.Text)
End If
End Sub
See this,
with simple code you can use this
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ListBox2.Items.Add(ListBox1.SelectedItem)
End Sub

Dynamic dropdown based on Radio selection

Good morning all! Myself and a co-worker are tasked with a system-wide scripting solution but neither of us are .NET programmers so we need your help.
We have a GUI that displays a radio selection box (3 options) that are the three sites where our hospitals are. We need to dropdown located on the form to fill with only the locations based on the selected radio option.
my gui http://web6.twitpic.com/img/40330741-85d91a5637f2445b322e62df17cf3351.4aef01c5-full.jpg
Here is the code behind we have so far (sorry, VB)
Public Class frmCEHLI
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CELocDataSet.dbo_Locations' table. You can move, or remove it, as needed.
Me.Dbo_LocationsTableAdapter.Fill(Me.CELocDataSet.dbo_Locations)
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
MsgBox("Submit button has been pressed")
End Sub
End Class
For the record the Location dropdown is currently databound but its a static SELECT statement which brings us all the locations but we'd prefer it to be cleaner if it only returned the locations based on Site. We are using Visual Basic 2008 Express Edition for development. Any help/code is appreciated, thanks!
Sorry not to respond back sooner, busy, and wanted to dig up a sample that did just what you were needing.
Create two comboboxes on your form. You can bind either fixed values, or from a table on the first combo. Then, from the property/events sheet, first set the "AutoPostBack" to TRUE, then on the events, click for the "SelectedIndexChanged" event to bring up some code.
The "Sender" object parameter will be the combobox itself, so you'll be able to analyse the property settings via debugging to find what key/value was chosen.
Then, run whatever query from your data querying control, business object, or whatever that gets your results, such as to a DataSet or DataTable.
Finally, set the datasource of your second combo to the above result query, set dataTextField and DataValueField and issue DataBind() to the combo.
That should get exactly what you need.
Then, when someone makes a selection from the second combo, you can have code within ITS "SelectedIndexChanged" event (also based on its AutoPostBack or actual submit button on the form).
Hope this helps.
I would create two combobox controls... One for the "where", then, on the InteractiveChange event by the user to post-back to the page using that answer for the second combobox of locations based on the "where" value of the first combo.