Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > SQL Question: UPDATE not working in VB.NET

Reply
Thread Tools

SQL Question: UPDATE not working in VB.NET

 
 
gordonta gordonta is offline
Junior Member
Join Date: Mar 2009
Posts: 8
 
      03-23-2011
I really hope I'm simply missing a syntax rule somewhere, but after extensive debugging I'm left with no other option but to beg you SQL Gurus out there.

My issue is that the UPDATE command, that increments the number of children a tree node has simply will not work. Everything else works fine, just no updating children. Please, I do know how messy the code is right now, clean up comes after functionality in my book

Thanks for your help!

Code:
     Try
            con.Open()
            Dim objcmd0 = New OleDb.OleDbCommand("SELECT id FROM SM_Tree WHERE sm_name = 'Situation'", con)
            Dim parentId As Integer = CInt(objcmd0.ExecuteScalar())
            Dim objCmd = New OleDb.OleDbCommand("INSERT INTO SM_Tree (parentId, sm_name, sm_data, children) VALUES (" & parentId.ToString & ", 'Event', '" & eventTextBox.Text & "', 0)", con)
            objCmd.ExecuteNonQuery()
            Dim objCmd2 = New OleDb.OleDbCommand("SELECT @@Identity", con)
            Dim id As Integer = CInt(objCmd2.ExecuteScalar())
            Dim objCmd4 = New OleDb.OleDbCommand("SELECT children FROM SM_Tree WHERE id = " & parentId.ToString & "", con)
            Dim oldChildrenValue As Integer = CInt(objCmd4.ExecuteScalar())
            oldChildrenValue += 1
            Dim sql As String = "UPDATE SM_Tree SET children = " + oldChildrenValue.ToString + " WHERE id = " + parentId.ToString
            Dim objCmd3 = New OleDb.OleDbCommand(sql, con)
            objCmd2.ExecuteNonQuery()
            con.Close()
            con = Nothing
        Catch ex As Exception
            con.Close()
            con = Nothing
            Server.Transfer("~/ErrorPage.aspx?errorMessage=" + ex.ToString)
        End Try
 
Reply With Quote
 
 
 
 
jlateehs jlateehs is offline
Junior Member
Join Date: Mar 2011
Posts: 3
 
      03-23-2011
is the ParentID a string or text value in your database or an int? What error are you getting when you debug?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access SQL to ASP SQL not working ... need help please David ASP General 4 09-28-2006 02:23 PM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
Re: SQL statement working in SQL Server but not in .aspx.cs page David Browne ASP .Net 0 08-21-2003 10:43 PM
Re: SQL statement working in SQL Server but not in .aspx.cs page William \(Bill\) Vaughn ASP .Net 0 08-21-2003 10:41 PM
Update to SQL Server is NOT Working someone ASP .Net 2 07-07-2003 11:04 PM



Advertisments