Problem Updating, Deleting and Inserting

Problem Updating, Deleting and Inserting

Postby alexh » Fri 29 Jun 2007 23:06

I am a PHP developer, previously with Java experience, who is now venturing on to C# with VS5 ... and I'm eager to get your program working.

I have read the forums extensively, as well as am in the middle of 2 C# ASP.NET programming books, and am still running into lots of errors.

I have properly updated the UpdateCommand but no matter what it seems to fail when I try to submit the updates, regardless if in gridview or detailview.

A common error I'm getting is:

Code: Select all
'price' parameter is missing at the statement


I am trying this with the simplest of statements trying to figure out where I am going wrong. I am usuing the visual designer to construct everything, and the select statements are coming up just fine.

Even with simple code I have problems
Code: Select all
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Auction-EditItem.aspx.cs" Inherits="Auction_EditItem" %>

<%@ Register Assembly="CoreLab.MySql.Web, Version=4.0.12.0, Culture=neutral, PublicKeyToken=09af7300eec23701"
    Namespace="CoreLab.MySql.Web" TagPrefix="cc1" %>





    Untitled Page



    "
        ProviderName="<%$ ConnectionStrings:CONNECTSTRING.ProviderName %>" SelectCommand="SELECT `item_id`, `description`, `retail`, `price`, `special` FROM `auction_items`" UpdateCommand="UPDATE auction_items SET price = ?, special = ? WHERE item_id = ? ">
         
               
               
               
         

   

            DataKeyNames="item_id" DataSourceID="MySqlDataSource1">
       
                            SortExpression="item_id" />
           
           
           
           

       

   

   






This is just one variation. I have attempted to many that it is rather exhausting and difficult for me to tell you at this point.

The parameter issue is the common problem I am having though. At first I was doing my UpdateCommand statements with SET name=@name type queries, but that wasn't working. I then switched to the question marks after reading a simlar thread, but am still having no luck.

- I am looking to a simple guide for C# users to make the simplest updates, deletions and inserts. Can you please e-mail or PM me this information.

- Any ideas as to what I am doing wrong at this point?

- I would rather interact with the queries one on one, instead of having it all server side, as right now I'm having much problems. I am unable to find any documentaiton on how to run a simple select query and have the result stored to an arraylist. Can I please have some examples.

Thanks for your prompt help.
alexh
 
Posts: 7
Joined: Fri 29 Jun 2007 22:57

Postby alexh » Sat 30 Jun 2007 16:29

I am imagining a lot of users have, or will have, this problem so I'll be glad to post some thoughts.

The problem, of course, is that the parameters being provided in my UpdateCommand is not ever being converted to the appropriate value. Part of the confusion for me is because many reference books tell me to use statements like name=$name while other places identify different methods.

For me, coding in C# in VS2005, I need to use the ?.

Code: Select all
"
            ProviderName="<%$ ConnectionStrings:Connect String.ProviderName %>" SelectCommand="SELECT item_id, quantity FROM auction_items WHERE item_id=2791" UpdateCommand="UPDATE auction_items SET quantity= ? WHERE item_id = ? ">
       
       



Then in my Page_Load method, that's where I define everything. For some reason, I'm not having success defining them with tags. But this works fine for me.

Code: Select all
protected void Page_Load(object sender, EventArgs e)
    {
        MySqlDataSource1.UpdateParameters.Add("quantity", quantity);
        MySqlDataSource1.UpdateParameters.Add("item_id", item_id);

    }


You should add them in the order the question marks are listed within your UpdateCommand. The first item in parenthesis in quotes, and the second is the value assigned to it at pageload.
alexh
 
Posts: 7
Joined: Fri 29 Jun 2007 22:57

Postby Alexey » Mon 02 Jul 2007 09:14

There is "Using parameters" article in our help documentation which is dedicated to this topic.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL