Visual Studio Development Bookmark and Share   
 index > Visual Studio Debugger > Exception in vb.Net while Updating Access DB
 

Exception in vb.Net while Updating Access DB

Hi.....
Can anyone help me out to handle this exception?


here it is.............
          The following coding is used to update a database row... but the following error occurs.......................
"Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any Key Column information"

The Exception Occured in the following coding In the line made Bold...


Public Class vwcnfrm
    Dim sql, a, o, le, user, sep, fsb, fhr, fhr1, fdt, fstra, fstro, fstrl, abstr, odstr As String
    Dim h As hme
    Dim i, i2, j, k, maxrows, maxrows1, maxrows2, l, m, er, ahlnth, i1, abarl, odarl, lvarl, temp%
    Dim ds, ds1, ds2 As New DataSet
    Dim dap, dap1, dap2 As OleDb.OleDbDataAdapter
    Dim con As New OleDb.OleDbConnection
    Dim arr(5), abar(65), odar(65), lvar(65) As String
    Dim hra(8) As String
    Dim connectionstring As String
    Dim mm As mrkatdnce
    Private Sub vwcnfrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        connectionstring = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = E:\OnlineEntrysh\2007-2011.mdb"
        con = New OleDb.OleDbConnection(connectionstring)
        con.Open()
        sql = "select * from staffdeta where subjname='" + fsb + "'"
        dap = New OleDb.OleDbDataAdapter(sql, con)
        dap.Fill(ds, "staffdet")
        maxrows = ds.Tables("staffdet").Rows.Count
        sql = "select * from studdeta"
        dap1 = New OleDb.OleDbDataAdapter(sql, con)
        dap1.Fill(ds1, "studdet")
        maxrows1 = ds1.Tables("studdet").Rows.Count
        sql = "select * from entry where dates='" + fdt + " 5'"
        dap2 = New OleDb.OleDbDataAdapter(sql, con)
        dap2.Fill(ds2, "entry2")
        lbltab.Text = j
        lbltod.Text = k
        lbltlv.Text = m
        lblab.Text = a
        lblod.Text = o
        lbllv.Text = le
    End Sub

    Public Sub New(ByVal a1 As String, ByVal p As Integer, ByVal q As Integer, ByVal r As Integer, ByVal ab As String, ByVal od As String, ByVal lv As String, ByVal sb As String, ByVal h As String, ByVal d As String)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        user = a1
        fsb = sb
        fhr = h
        fdt = d
        j = p
        k = q
        m = r
        If (ab = "" Or ab = " " Or ab = "  " Or ab = "   ") Then
            a = "nil"
        Else
            a = ab
        End If

        If (od = "" Or od = " " Or od = "  " Or od = "   ") Then
            o = "nil"
        Else
            o = od
        End If
        If (lv = "" Or lv = " " Or lv = "  " Or lv = "   ") Then
            le = "nil"
        Else
            le = lv
        End If
        Me.Show()
        hra = Split(fhr)
        abar = Split(ab)
        odar = Split(od)
        lvar = Split(le)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'add the database details
        i = 0
        ahlnth = hra.Length
        abarl = abar.Length
        odarl = odar.Length
        lvarl = lvar.Length

        Dim cb As New OleDb.OleDbCommandBuilder(dap)
        Dim cb1 As New OleDb.OleDbCommandBuilder(dap1)
        Dim cb2 As New OleDb.OleDbCommandBuilder(dap2)
        Dim nr As DataRow = ds2.Tables("entry2").NewRow()
        fstra = fsb + " " + a
        fstro = fsb + " " + o
        fstrl = fsb + " " + le
        ' details to insert into studdet
        i = 0
        i2 = 0
        While (i2 < ahlnth)
            While (i < abarl)
                temp = abar(i)
                ds1.Tables("studdet").Rows(temp - 1).Item(2) += 1
                i = i + 1
            End While
            i = 0
            While (i < lvarl)
                temp = lvar(i)
                ds1.Tables("studdet").Rows(temp - 1).Item(2) += 1
                i = i + 1
            End While
            i = 0
            i2 += 1
        End While
        'details to insert into staffdet
        i = 0
        While (i < ahlnth)
            ds.Tables("staffdet").Rows(0).Item("hours") += 1
            i += 1
        End While
        'details to insert into entry
        i = 0
        While (i < ahlnth)
            fhr1 = hra(i)
            maxrows2 = ds2.Tables("entry2").Rows.Count
            If (maxrows2 <> 0) Then
                MsgBox("inside if")
                MsgBox("updation")
                ds2.Tables("entry2").Rows(0).Item(fhr1 + "absent") = fstra
                ds2.Tables("entry2").Rows(0).Item(fhr1 + "od") = fstro
                ds2.Tables("entry2").Rows(0).Item(fhr1 + "leave") = fstrl
            ElseIf (maxrows2 = 0) Then
                MsgBox("else")
                MsgBox("insertion")
                nr("dates") = fdt + " 5"
                nr(fhr1 + "absent") = fstra
                nr(fhr1 + "od") = fstro
                nr(fhr1 + "leave") = fstrl
                ds2.Tables("entry2").Rows.Add(nr)
                dap2.Update(ds2, "entry2")
            End If
            i = i + 1
        End While
        dap1.Update(ds1, "studdet")
        'dap2.Update(ds2, "entry2")
        dap.Update(ds, "staffdet")  <---------Exception occured in this position
        con.Close()
        Me.Hide()
        h = New hme(user)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        con.Close()
        mm = New mrkatdnce(user, fsb, fhr, fdt, lblab.Text, lblod.Text, lbllv.Text)
        Me.Hide()
    End Sub
End Class



Please help me out to solve this or say some method to update the database..........................
Thank U................

dhayanand  Tuesday, October 06, 2009 9:24 AM
I did not look through your code ... but from the error message ...

Is there a primary key on the table?
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Tuesday, October 06, 2009 7:01 PM
Hello,

I agree with DeborahK, please check if we have set a primary key in table (staffdeta in this case).

Best regards,
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback, please tell us.
Welcome to the All-In-One Code Framework!
Roahn Luo  Wednesday, October 07, 2009 2:33 AM
I did not look through your code ... but from the error message ...

Is there a primary key on the table?
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Tuesday, October 06, 2009 7:01 PM
Hello,

I agree with DeborahK, please check if we have set a primary key in table (staffdeta in this case).

Best regards,
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback, please tell us.
Welcome to the All-In-One Code Framework!
Roahn Luo  Wednesday, October 07, 2009 2:33 AM
Hi...

Thanks guys......... There was no primary key in table so only error occured i found.......

Thank U..
Regards
Dhayanand.B
dhayanand  Wednesday, October 07, 2009 9:51 AM
Hi

Thanks. I found out the error.......

Thank U
Regards
Dhayanand.B
dhayanand  Wednesday, October 07, 2009 9:52 AM

You can use google to search for other answers

Custom Search

More Threads

• Debugger doesn't work after migrating
• Visual Studio Debugging shows incorrect values
• Debugger Visualizer
• debug process spawned by other process...
• Can't run any programs?
• DebuggerVisualizer evaluation time out
• Can my app find out when debugger does 'stop debugging' (shift-f5)?
• After installing VS 2003 SP1 "Error while trying to run project: Unable to start debugging"
• can't find the Immediate window
• XPE - Remote debugging