7 Replies - 231 Views - Last Post: 02 December 2013 - 04:28 PM Rate Topic: ***** 1 Votes

#1 djasy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-February 12

no error with the stored procedure, but no update in database(MSAccess

Posted 02 December 2013 - 05:12 AM

hi!
i'm trying to update some informations in my database through a stored procedure called in asp.net(C#), i'm using an Access dataBase. it's a shoppingCart. i want to update the quantity of an item once it's already in the shoppingCart. i even use a message to be displayed if something goes wrong or not. it displayed that it succeded but the change doesn't happen. i got the same problem also when i try to add an existing item in the shopping cart. the update doesn't execute and i got no error! but it seems clear to me !
//méthode pour mettre à jour les données dans la table
public static bool MajProduit(string produit, int qte)
{
    //on obtient l'objet configuré DbCommande
    DbCommand m_cmd = LibAccesGenerique.CreerCmd();
    //on établit la procédure stockée
    if (qte <= 0)
        m_cmd.CommandText = "ShoppingCartDeleteProduits";
    else
        m_cmd.CommandText = "ShoppingCartUpdateProduit";
    //on créer les paramètres
    DbParameter m_param = m_cmd.CreateParameter();
    m_param.ParameterName = "@CartID";
    m_param.Value = ShoppingCartId;
    m_param.DbType = DbType.String;
    m_param.Size = 36;
    m_cmd.Parameters.Add(m_param);
    //on en crée un autre produit
    m_param = m_cmd.CreateParameter();
    m_param.ParameterName = "@Produit";
    m_param.Value = produit;
    m_param.DbType = DbType.Int32;
    m_cmd.Parameters.Add(m_param);
    //parametre qté
    m_param = m_cmd.CreateParameter();
    m_param.ParameterName = "@Quantite";
    m_param.Value = qte;
    m_param.DbType = DbType.Int32;
    m_cmd.Parameters.Add(m_param);
    //on retourne vrai si l'opération réussie
    try
    {
        //on execute la procédure stockée et retourne vrai, si la méthode s'est bien exécutée
        return (LibAccesGenerique.ExecuteNonQuery(m_cmd) != -1);
    }
    catch
    {
        return false;
    }
}


this is my method for updating item. it's only working with the delete procedure!

Is This A Good Question/Topic? 0
  • +

Replies To: no error with the stored procedure, but no update in database(MSAccess

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,570
  • Joined: 12-December 12

Re: no error with the stored procedure, but no update in database(MSAccess

Posted 02 December 2013 - 05:43 AM

Please post the text of the stored procedure ShoppingCartDeleteProduits.

Have you tested this procedure separately, outside of your ASP application?

This post has been edited by andrewsw: 02 December 2013 - 05:45 AM

Was This Post Helpful? 0
  • +
  • -

#3 djasy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-February 12

Re: no error with the stored procedure, but no update in database(MSAccess

Posted 02 December 2013 - 06:14 AM

@andrewsw: yes i did, when i execute the querry in access, it's working without a probleme! here are my queries:
ShoppingCartDeleteProduits
DELETE *
FROM ShoppingCart
WHERE CartID = @CartID and ProduitID = @ProduitID;


ShoppingCartUpdateProduit
UPDATE ShoppingCart SET Quantite = @Quantite, DateAjoute = NOW()
WHERE ProduitID = @ProduitID AND CartID = @CartID;


Was This Post Helpful? 0
  • +
  • -

#4 jhouns  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 100
  • Joined: 21-December 09

Re: no error with the stored procedure, but no update in database(MSAccess

Posted 02 December 2013 - 06:38 AM

I can't see anything obviously wrong. Have you tried analysing the logic on line 34? I'd put a break point on there and check the m_cmd object properties/params, attempt to temporarily store it in a variable for debugging purposes as well to check the return of the method call. i.e. change
return (LibAccesGenerique.ExecuteNonQuery(m_cmd) != -1);



to
int tmp = LibAccesGenerique.ExecuteNonQuery(m_cmd);
return (tmp != -1);



Then when debugging, you can check the return value of tmp easily to see if the result is coming back in a way you expect.

If m_cmd and it's list of parameters are all okay when ExecuteNonQuery is called, yet tmp isn't what you expect then the issue lies in either the ExecuteNonQuery method or the stored proc.

I'm not sure if it's relevant but here's an article on ADO.NET for calling stored procedures in case it helps you.
Was This Post Helpful? 1
  • +
  • -

#5 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3168
  • View blog
  • Posts: 9,581
  • Joined: 05-May 12

Re: no error with the stored procedure, but no update in database(MSAccess

Posted 02 December 2013 - 06:44 AM

I don't use Access, but as I recall, some older version of the Access database do no support stored procedures.
Was This Post Helpful? 1
  • +
  • -

#6 Momerath  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 995
  • View blog
  • Posts: 2,390
  • Joined: 04-October 09

Re: no error with the stored procedure, but no update in database(MSAccess

Posted 02 December 2013 - 11:02 AM

View Postdjasy, on 02 December 2013 - 05:14 AM, said:

DELETE *
FROM ShoppingCart
WHERE CartID = @CartID and ProduitID = @ProduitID;


The parameters you are supplying in your stored procedure are not the same parameters that .NET uses when you specify a command. You have two different sets of parameters (those supplied to the stored procedure, and those used in the stored procedure). Since you don't 'link' the two, the values passed are ignored.

Check out this page for some examples of how the stored procedure should look, and how to pass values (and get the return value) from a stored procedure.
Was This Post Helpful? 2
  • +
  • -

#7 djasy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-February 12

Re: no error with the stored procedure, but no update in database(MSAccess

Posted 02 December 2013 - 02:52 PM

@Momerath: yes i know, i used that procedure, just to test if the method was working, and it is without a problem. if in the textBox, the user put zero, it deletes directly in the cart when the update button is clicked.
@Skydive: it's working with queries.
@jhouns: i'm having the same trouble with the addToCart method: the first time i execute the method, that means if the article was not in the cart, the temp variable returns true, but if i want to execute the second time(update), the same article, it returns false. the same problem happens with the majProduit method. if i try to change the quantity of any article in the cart and update it, it doesn't work. the previous quantity remains the same. but if i execute the query which is linked with the method, manually in the database, it works.
Was This Post Helpful? 0
  • +
  • -

#8 djasy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-February 12

Re: no error with the stored procedure, but no update in database(MSAccess

Posted 02 December 2013 - 04:28 PM

Hello! :D
i just resolved the problem, thank you for your posts.
The problem was with the order of the parameters. so i was supposed to put them in order like they're placed in the database. i did it and it worked!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1