Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2007, 11:10 AM
Authorized User
 
Join Date: Dec 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to brawny4
Default !!HELP! trying to update an Access database

I have the following code:

        Dim updateConnection As OleDbConnection = GetConnection()
        Dim updateSQL As String = _
        "UPDATE Last_Incident_nbr " _
        & "Set Last_Incident_Nbr = @new_incident_Nbr," _
        & "Last_Incident_date = @newDate " _
        & "where last_incident_date = @last_Incident_date;"
        Dim updateCommand As New OleDbCommand(updateSQL, updateConnection)
        updateCommand.CommandText = CommandType.StoredProcedure
        updateCommand.Parameters.AddWithValue("@Last_Incid ent_Nbr", NewIncident)
        updateCommand.Parameters.AddWithValue("@Last_Incid ent_date", newDate)

        Try
            Dim intRowsaffected As Integer
            updateConnection.Open()
            intRowsaffected = updateCommand.ExecuteNonQuery()

            updateConnection.Close()
            MessageBox.Show(intRowsaffected, "Finished Update")
        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.GetType.ToString)
        End Try

and I am getting the error message:

"INVALID SQL STATEMENT, EXPECTED "DELETE", "INSERT", "PROCEDURE", "SELECT" OR "UPDATE".

Can anyone tell me what I am doing wrong?


mfb
__________________
mfb
 
Old April 24th, 2007, 11:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mmm.. and if you try to actually pass the sql to the command ;)???

Code:
updateCommand.CommandText = CommandType.StoredProcedure
is wrong, should be:
Code:
updateCommand.CommandType = CommandType.StoredProcedure
and that's why you were loosing your sql...


HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
 
Old April 24th, 2007, 01:47 PM
Authorized User
 
Join Date: Dec 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to brawny4
Default

I made those changes to be the following but now I get a new error:

Dim updateConnection As OleDbConnection = GetConnection()
        Dim updateCommand As New OleDbCommand()
        updateCommand.Connection = updateConnection
        updateCommand.CommandType = CommandType.Text
        updateCommand.CommandText = _
         "UPDATE Last_Incident_nbr " _
        & "Set Last_Incident_Nbr = @new_incident_Nbr," _
        & "Last_Incident_date = @newDate " _
        & "where last_incident_date = @last_Incident_date;"
        updateCommand.Parameters.AddWithValue("@Last_Incid ent_Nbr", NewIncident)
        updateCommand.Parameters.AddWithValue("@Last_Incid ent_date", newDate)


The error is: "NO VALUE GIVEN FOR ONE OR MORE REQUIRED PARAMETERS"

mfb
 
Old April 24th, 2007, 02:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. that's another problem.. the sql is wrong.. test it on the database and you will see.. probably you misspelled a field name or the table name... or you are sending to the sql few parameters (i see 3 on the sql, are you sending 3???)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
 
Old April 24th, 2007, 02:07 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ummm You are you using 3 parameters in your query, but only add 2 to your connection.

You use: @new_incident_Nbr, @newDate, and @last_incident_date

But you only declare @Last_incident_Nbr and @Last_Incident_date

Add another
updateCommand.Parameters.AddWithValue("@newdate", newDate)

to correct the problem.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help!!! Cannot Update, Delete from Access database dreamzentrue ADO.NET 7 November 3rd, 2005 06:11 PM
Access database won't update? jula Access ASP 8 September 26th, 2004 05:46 PM
Allow SQL to update an Access database levinho Classic ASP Databases 7 November 11th, 2003 08:32 AM
Database update access inershado Access ASP 1 September 23rd, 2003 11:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.