Original Post: http://www.vbdotnetforums.com/sql-server/62234-need-update-sql-server-values-txtbox.html
Using: SQL Server 2014, VS2015, VB
This works perfect thanks to jmcilhinney. It fills the Datagridview and when I click on a row it populates the corresponding textboxes.
What is not working is that when I make changes in the textboxes I press a command button to update the SQL Server with the new values and nothing happens, the data doesn't update. This is where I am stuck.
The following Code is working to populate the Datagridview and Textboxes:
?Button to display all records in the datagridview
Private Sub btnViewAll_Click(sender As Object, e As EventArgs) Handles btnViewAll.Click
?Connection to the Server
Using connection3 As New SqlConnection("SERVER=x.x.x.x;database=ITDatabase;trusted_connection=yes;")
?Variables declarations
Dim cmd As New SqlCommand("SELECT AssetNo [ASSET NO], t2.TYPE
From ASSETINFO t1
INNER Join TypeInfo t2 on t1.TYPEID = t2.TYPEID
Order By AssetNo ASC;", connection3)
Dim Adpt As New SqlDataAdapter(cmd)
Dim table As New DataTable
Adpt.Fill(table)
bsAllData.DataSource = table
dataGridAssetEdit.DataSource = bsAllData
txtAssetNo2.DataBindings.Clear()
txtAssetNo2.DataBindings.Add("Text", Me.bsAllData, "ASSET NO")
cboAssetType2.DataBindings.Clear()
cboAssetType2.DataBindings.Add("Text", Me.bsAllData, "Type")
End Sub
?Button to Update
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
?Code used but doesn?t do anything.
bsAllData.EndEdit()
Adpt.Update(table)
End Sub
Regards,
Using: SQL Server 2014, VS2015, VB
- I have a Datagridview that fills with a DataTable (Table).
- I have several Textboxes that are bind with their corresponding values from the binding Source (bsAllData)
This works perfect thanks to jmcilhinney. It fills the Datagridview and when I click on a row it populates the corresponding textboxes.
What is not working is that when I make changes in the textboxes I press a command button to update the SQL Server with the new values and nothing happens, the data doesn't update. This is where I am stuck.
The following Code is working to populate the Datagridview and Textboxes:
?Button to display all records in the datagridview
Private Sub btnViewAll_Click(sender As Object, e As EventArgs) Handles btnViewAll.Click
?Connection to the Server
Using connection3 As New SqlConnection("SERVER=x.x.x.x;database=ITDatabase;trusted_connection=yes;")
?Variables declarations
Dim cmd As New SqlCommand("SELECT AssetNo [ASSET NO], t2.TYPE
From ASSETINFO t1
INNER Join TypeInfo t2 on t1.TYPEID = t2.TYPEID
Order By AssetNo ASC;", connection3)
Dim Adpt As New SqlDataAdapter(cmd)
Dim table As New DataTable
Adpt.Fill(table)
bsAllData.DataSource = table
dataGridAssetEdit.DataSource = bsAllData
txtAssetNo2.DataBindings.Clear()
txtAssetNo2.DataBindings.Add("Text", Me.bsAllData, "ASSET NO")
cboAssetType2.DataBindings.Clear()
cboAssetType2.DataBindings.Add("Text", Me.bsAllData, "Type")
End Sub
?Button to Update
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
?Code used but doesn?t do anything.
bsAllData.EndEdit()
Adpt.Update(table)
End Sub
Regards,