Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27348

can not update table in sql server with vb.net datagridview

$
0
0
Hello,

I've got a dgv where the user can change the cells.
with a button I'm trying to update.
The code gives the message that it works, but the table
in slq server isn't updated.

here's the code:

[CODE]

Imports System.Text
Imports System.Data.SqlClient

Public Class TotaalNazicht

Dim sBuilder As SqlCommandBuilder
Dim sCommand As SqlCommand
Dim sAdapter As SqlDataAdapter
Dim sDs As DataSet
Dim sTable As New DataTable

Private TaKlant As DataTable

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con = getConnect()

Try

Dim Cmd6 As SqlCommand = con.CreateCommand
sAdapter = New SqlDataAdapter(Cmd6)

Cmd6.CommandText = "select TOP 5 * from ValutaUnderwear order by Dagteller desc "

sAdapter = New SqlDataAdapter(Cmd6)
Dim sTable As New DataTable
sAdapter.Fill(sTable)
DataGridView6.DataSource = sTable
DataGridView6.Columns(18).Visible = False

con.Close()
Catch
MessageBox.Show("Error occurred!")

End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim con As New SqlConnection

Try
Dim sBuilder As SqlCommandBuilder
sTable.AcceptChanges()
sBuilder = New SqlCommandBuilder(sAdapter)
Me.sAdapter.Fill(Me.sTable)
sAdapter.Update(sTable)
MsgBox("Changes Done")

Catch ex As Exception
MsgBox(ex.ToString)

End Try

End Sub
End Class

[ENDCODE]

Can someone see what I do wrong?

Marijke

Viewing all articles
Browse latest Browse all 27348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>