Using VB.net DataGrid view to interact with SQL DB. Update/Delete/Add - sql

Setup Information
I have "Form1" with a DataGrid View ("DataGridView1") which populates with Data from an SQL server table.
It's a simple table, with about 10 records.
The table used is "jamesTestVBlol"
The dataset is named "DataSetJames.xsd"
I believe the table adaptor is called "JamesTestVBlolTableAdaptor"
Question
Is there a way, I can update a record and send these changes back to the server.
e.g. Column 1, record 1 I would like to change to "TEST" and update this table on the server.
The only code I have is:
Public Class Form1
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 'DataSetJames.jamesTestVBlol' table.' You can move, or remove it, as needed.
Me.JamesTestVBlolTableAdapter.Fill(Me.DataSetJames.jamesTestVBlol)
End Sub
End Class
Could anyone help me with where I need to look?
I've tried to read several online tutorials, but generally they are above my head.
Thanks,
James.

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.

Update changes made in datagridview into Access 2016

I made a connection with an Access database (Access 2016) using dataset, bindingsource, tableadapter, bindingnavigator, and datagridview.
It works, I can navigate in the datagridview, make changes, add and delete records in the datagridview, but these changes don't appear in the Access DB.
Data is loaded with:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'FacturatieDataSet.Catalogus' table. You can move, or remove it, as needed.
CatalogusTableAdapter.Fill(FacturatieDataSet.Catalogus
End Sub
For deleting I use:
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
CatalogusBindingSource.RemoveCurrent()
CatalogusTableAdapter.Update(FacturatieDataSet.Catalogus)
End Sub
I'm new with VB 2015, I'm not a programmer, I do this for personnal study.
What is an (easy) solution to my problem?
You fill the datagridview but you don't update it (except when you delete a record).
Look up a tutorial on how to handle basic CRUD operations with a datagridview.

vb.net connects to database access

im really new to this language so this is so simple please answer
Me.InfoBindingSource.RemoveCurrent()
i only have id t on my delete button do i have to adsome codes? knows anyone?
i've searched some sites and it is the only code they say. i connected it and actually worked on add. but with delete it dont.
Do i need to move something.. like files?
i've tried everything this is my last hope. thanks for the answer :)
here is the whole code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.InfoBindingSource.RemoveCurrent()
End Sub
That RemoveCurrent method will mark the current row in the bound DataTable as Deleted. Just like when adding or editing rows though, you still have to call Update on your data adapter or table adapter to save that change back to the database.

VB.Net Table Adapter (Visual Studio) - NULLReferenceException

I'm a beginner when it comes to VB based languages and have never worked with Table Adapters. I have a Data Source with the following tables. Previously, I was using a different database and now switched to a different one. The new one has the same tables except the values may or may not be different. I'm getting a "NULLReferenceException was unhandeled". I checked the Data Sources to make sure that table existed and it does...Could it be because the table adapter exists with the previous database (most of the tables have the same exact name in the new DB as the previous DB)? Any help will be appreciated!
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 'CEDOPT_Model_HCCDataSet.PriceJointSensitivity' table. You can move, or remove it, as needed.
Me.PriceJointSensitivityTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.PriceJointSensitivity)
Me.Yield_Dist_ShapeTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Yield_Dist_Shape)
Me.PriceSensitivityCurvesTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.PriceSensitivityCurves)
Me.Factor_RevPlan_CalibrateTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_RevPlan_Calibrate)
Me.APH_RangesTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.APH_Ranges)
Me.Temp_state_updateTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.temp_state_update)
Me.Ref_StateTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.ref_State)
Me.PriceCVTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.PriceCV)
Me.CV_to_LossTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.CV_to_Loss)
Me.Factor_PriceElection_HCCTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_PriceElection_HCC)
'Me.Factor_PracticeTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_Practice)
Me.Factor_InsPlan_HCCTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_InsPlan_HCC)
Me.Factor_Crop_HCCTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_Crop_HCC)
Me.Factor_Coverage_HCCTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_Coverage_HCC)
Me.Factor_County_HCCTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_County_HCC)
Me.Factor_APHBand_HCCTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_APHBand_HCC)
Me.Factor_AcreBand_HCCTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_AcreBand_HCC)
Me.BadPIndexTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.BadPIndex)
'Added 3/3/2015 to accomodate for weather variable
Me.Factor_DnSolTableAdapter.Fill(Me.CEDOPT_Model_HCCDataSet.Factor_LTDnSol)
End Sub

Simple, but I'm stuck ....Updating a DataSet using code

I have a simple Windows form in VB: textbox bound thru an adapter and a bindingsource to my dataset.
I have a button that on Click I want it to update the database. The form loads and the first data row shows in the textbox, I change the text then click my button but no update happens.
Any ideas what I'm doing wrong, or how I should do this??
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AToolsTableAdapter.Fill(Me.Qedsandb_TroyDataSet.aTools)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AToolsTableAdapter.Update(Qedsandb_TroyDataSet.aTools)
End Sub
End Class
Assuming the click event runs(?), TableAdapters based on a query (a join) do not, by default, have the ability to update the database. The name of your binding source suggests that you are using a query.
MSDN: TableAdapter Overview
The update functionality of a TableAdapter is dependent on how much
information is available based on the main query provided in the
TableAdapter Wizard. For example, TableAdapters that are configured to
fetch values from multiple tables (JOINs), scalar values, views, or
the results of aggregate functions are not initially created with the
ability to send updates back to the underlying database. However, you
can configure the INSERT, UPDATE and DELETE commands manually in the
Properties window.
You don't appear to be moving the data back from the form to the dataset. Try calling EndEdit on your bindingsource.