tags:

views:

342

answers:

6

My UPDATE command fails to change any date in the table while very similar SELECT and DELETE commands work. When I change the UpdateParameters to invalid choices, the code behind command throws an error, buy when the parameters are correct, nothing hapens.

Code behind to activate DELETE (which works)

protected void Button2_Click(object sender, EventArgs e)
{
    this.AccessDataSource6.Delete();
}

Code behind to activate UPDATE (which does seem to have any effect on the data)

protected void Button1_Click(object sender, EventArgs e)
{
    this.AccessDataSource6.Update();
}

The AccessDatasource, its SQL commands and parameters

   <asp:AccessDataSource ID="AccessDataSource6" runat="server" DataFile="~/App_Data/ASPNetDB.mdb" 
    SelectCommand="SELECT [PracticeDate], 
                          [StartTime], 
                          [EndTime], 
                          [Division], 
                          [TeamStr], 
                          [FieldName] 
    FROM [vw_fbScheduleFull]
    WHERE (([LocationID] = ?) 
       AND ([DayName] = ?) 
       AND ([PracticeDate] &gt;= ?) 
       AND ([PracticeDate] &lt;= ?) 
       AND ([StartTime] = ?))
    ORDER BY [PracticeDate], [FieldName]"

    UpdateCommand="UPDATE fbPracticeSlot 
    SET StartTime = ?, EndTime = ?
    WHERE ID IN (
       SELECT [PracticeSlotID] 
       FROM [vw_fbScheduleFull] 
       WHERE (([LocationID] = ?) 
          AND ([DayName] = ?) 
          AND ([PracticeDate] &gt;= ?) 
          AND ([PracticeDate] &lt;= ?) 
          AND ([StartTime] = ?))
       )" 

   DeleteCommand="DELETE FROM fbPracticeSlot 
    WHERE ID IN (
       SELECT [PracticeSlotID] 
       FROM [vw_fbScheduleFull]
       WHERE (([LocationID] = ?) 
          AND ([DayName] = ?) 
          AND ([PracticeDate] &gt;= ?) 
          AND ([PracticeDate] &lt;= ?) 
          AND ([StartTime] = ?)) 
       )">

<SelectParameters>
       <asp:ControlParameter ControlID="DropDownListLocation" Name="LocationID" PropertyName="SelectedValue" Type="Int32" />
       <asp:ControlParameter ControlID="DropDownListDOW" Name="DayName" PropertyName="SelectedValue" Type="String" />
       <asp:ControlParameter ControlID="DropDownListStartDate" Name="PracticeDate" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListEndDate" Name="PracticeDate2" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListStartTime" Name="StartTime" PropertyName="SelectedValue" Type="DateTime" />
</SelectParameters>

<UpdateParameters>
       <asp:ControlParameter ControlID="DropDownListNewStart" Name="NewStartTime" PropertyName="SelectedValue" Type="DateTime" />                  
       <asp:ControlParameter ControlID="DropDownListNewEnd" Name="NewEndTime" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListLocation" Name="LocationID" PropertyName="SelectedValue" Type="Int32" />
       <asp:ControlParameter ControlID="DropDownListDOW" Name="DayName" PropertyName="SelectedValue" Type="String" />
       <asp:ControlParameter ControlID="DropDownListStartDate" Name="PracticeDate" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListEndDate" Name="PracticeDate2" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListStartTime" Name="StartTime" PropertyName="SelectedValue" Type="DateTime" />
</UpdateParameters>

<DeleteParameters>
       <asp:ControlParameter ControlID="DropDownListLocation" Name="LocationID" PropertyName="SelectedValue" Type="Int32" />
       <asp:ControlParameter ControlID="DropDownListDOW" Name="DayName" PropertyName="SelectedValue" Type="String" />
       <asp:ControlParameter ControlID="DropDownListStartDate" Name="PracticeDate" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListEndDate" Name="PracticeDate2" PropertyName="SelectedValue" Type="DateTime" />
       <asp:ControlParameter ControlID="DropDownListStartTime" Name="StartTime" PropertyName="SelectedValue" Type="DateTime" />
</DeleteParameters>

</asp:AccessDataSource>

Please help me understand why the update is not changing data.

It seems that I either need to write UpdateCommands with hard coded parameters for the values to change or write a DeleteCommand and InsertCommand for each update that I want to perform. Please help me find some way to avoid that sort of kludge.

+1  A: 

Usually a valid SQL Update statement fails without error because no records match your WHERE condition. Have you set a breakpoint on the Button_Click event and looked at the value of the parameters?

MikeB
The WHERE condition of the UPDATE parameters are exactly the same as the WHERE condition of the DELETE parameters. However, I will try this too.
Degan
Yes, I did check the parameters. My thought is that AccessDatasource does not support parameters for the values to be SET in an UPDATE command. In the Access GUI, it is similarly difficult (perhaps not possible without VBA behind) to parameterize the columns to be SET in an UPDATE command
Degan
The only other thing I can think of is if you are using Bind() in your EditTemplate. Try changing it to Eval() if you are.
MikeB
AccessDatasource may not support parameterized values in the SET statement, but Jet/ACE SQL certainly supports it.
David-W-Fenton
A: 

I might get downvoted for this useless answer but I couldn't help noticing that you are using xml constants for the symbols > and < within your UPDATE clause....Do a response write on the UpdateCommand to verify that the sql is valid, copy that SQL and paste it into Access and see if it is accepted by Access itself? Sorry if this sounds lame and stupid *sniff*

Hope this helps, Best regards, Tom.

tommieb75
Just looked at it again, why is the table name in the SQL command for UpdateCommand has no brackets around it yet you have it for the SelectCommand. I have noticed a few things lacking, there is no mention of what version of MS-Access you are using and what is the front end doing exactly? Did the connection via ADO.NET get expired as a result of connection pooling under IIS? Which version of IIS are you using?
tommieb75
By the way, are you opening and closing the connection explicitly on the server side, perhaps forgetting to dispose the connection instead of a using clause. I was looking at this here...http://stackoverflow.com/questions/686970/why-would-accessdatasource-return-different-results-to-query-in-acces
tommieb75
The link is wrong...it should be http://stackoverflow.com/questions/686970/why-would-accessdatasource-return-different-results-to-query-in-accessMy bad! Meh! :(
tommieb75
The XML constants are written out by the IDE (Visual Web Developer 2008 Express). I have not had a problem with them elsewhere, but I will try switching them. I am not explictily opening andclosing the conection. Access 2007. I am testing this locally using Visual Wb Developer 2008 Express. When I change the parameters to invalid values, I get an error. No error with good values. My present guess is tht AccessDataSource is not properly handling UpdateCommand.
Degan
Changing the XML constants to the symbols had no affect.
Degan
A: 

Try and catch the Updating event, to see what is the SQL that gets executed when you run AccessDataSource6.Update();

Inside the event, you can get hold of the underlying SQL by looking at the instance of SQLDataSourceCommandEventArgs's Command property.

That should be the starting point.
If the SQL looks OK, try running that on your MDB to see, if it raises any error at all.

shahkalpesh
Shahkalpesh, There was another answer previously, that had code examples for displaying the parameters. For some reason it is gone. As a comment to that answer, I replied that all of the parameters are coming through as expected. My thought is that AccessDatasource does not support parameters for the values to be SET in an UPDATE command. In the Access GUI, it is similarly difficult (perhaps not possible without VBA behind) to parameterize the columns to be SET in an UPDATE command.
Degan
shahkalpesh
@Shahkalpesh, At this point, the earliest for be to attempt this will be about 4-5 days from now.
Degan
A: 

This may not be the answer, I don't use the data adpaters like this much, but I have noticed in the past that the order of the parameters being passed to a query against an access database matters.

Your list of update parameters does not match the order of the parameters in your update query - this may just be your issue (providing you've done the above and checked that there is something that matches your where clause).

Paddy
That's the first thing I looked for. The parameters appear to be in the correct order. You are right, however, that order is all-important with OleDb.
MikeB
The order of the parameters is correct.
Degan
Sorry, didn't read that correctly.
Paddy
A: 

First, after you update the database, what do you do? I have run into an issue where the access db is in your project and you it is automatically set to copy always to the output directory. If you run the code and then restart it, the access db is blown away. Just a thought, but one to make sure you are not doing.

Wade73
A: 

From reading your question and all the follow-up I can see you've covered just about all the bases. I do have one thought, and it's really a shot in the dark. Perhaps the Access parser doesn't recognize the target columns as belonging to the table you're updating. Have you tried:

    UpdateCommand="UPDATE fbPracticeSlot 
    SET fbPracticeSlot.StartTime = ?, fbPracticeSlot.EndTime = ?
    WHERE ID IN (
    SELECT [PracticeSlotID] 
    FROM [vw_fbScheduleFull] 
    WHERE (([LocationID] = ?) 
      AND ([DayName] = ?) 
      AND ([PracticeDate] &gt;= ?) 
      AND ([PracticeDate] &lt;= ?) 
      AND ([StartTime] = ?))
   )"

Since Access supports multi-table updates, it is possible that the parser is confused because of the presence of a column named StartTime inside of the nested select.

In any case, it seems like you've tried everything else. Good luck!

Paul Keister