Update of single row in datagridview

AvgJoe

New member
Joined
Sep 27, 2006
Messages
1
Programming Experience
1-3
Hello, still quite new to VB.NET so excuse any stupidities.
I have a datagridview which lists system users,the user selects a user and then has the option of deleteing the user. What happens is that, that record's deleted field should get updated to true, the datagridview SQL only shows where the deleted flag is false.
The error I get is the following
"Dynamic SQL generation is not supported against multiple base tables"
The error line is also indicated below

I understand that the code generated update statements only work on single tables, but I need a way around this, if anyone could point me in the
right direction, it would be greatly appreciated.

On another note, I was wondering how my datagridview could pickup/display changes made by other users on the records I'm viewing
in my datagridview (The application is on multiple client pcs connected to a central SQL server).

Many Thanks

Code follows:

VB.NET:
Public Class frmSystemUsers
    Public table As New DataTable
    Public DataAdapter As SqlClient.SqlDataAdapter
    Private Sub frmSystemUsers_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
 Dim strSQL As String
        strSQL = "SELECT     tblSysUsers.SysUserID, tblSysUsers.UserName, tblUserLevels.UserLevel AS [User Level],deleted " & _
                " FROM         tblSysUsers LEFT OUTER JOIN " & _
                " tblUserLevels ON tblSysUsers.UserLevelID = tblUserLevels.UserLevelID " & _
                " WHERE (tblSysUsers.Deleted = 0) "
        DataAdapter = New SqlClient.SqlDataAdapter(strSQL, Conn)
        Dim commandBuilder As New SqlClient.SqlCommandBuilder(DataAdapter)
        table.Locale = System.Globalization.CultureInfo.InvariantCulture
        DataAdapter.Fill(table)
        dbBindingSource.DataSource = table
        Me.lstSystemUsers.DataSource = dbBindingSource
        table.PrimaryKey = New DataColumn() {table.Columns("SysUserID")}
    End Sub
    Private Sub lstSystemUsers_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstSystemUsers.SelectionChanged
 
 If Not (Me.lstSystemUsers.CurrentRow Is Nothing) Then
            sysUserID = Me.lstSystemUsers.CurrentRow.Cells("SysUserID").Value
        End If
    End Sub
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
 
 If MsgBox("Are you sure you want to delete this User?", MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation) = MsgBoxResult.Yes Then
 
            Dim oDR2 As DataRow
            oDR2 = table.Rows.Find(Me.lstSystemUsers.CurrentRow.Cells("sysuserid").Value)
 
            oDR2.BeginEdit()
            oDR2("deleted") = True
            oDR2.EndEdit()
 
            DataAdapter.Update(table) 'PROBLEM LINE
            table.AcceptChanges()
            DataAdapter.Fill(table)
            Me.lstSystemUsers.Refresh()
 
        End If
    End Sub
 
End Class
 
Back
Top