Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have inherited some ASP.NET code that I need to update which has resulted in my needing to change the ASP SqlDataSource's UpdateCommandType from a string (hard coded SQL Update statement) to a stored procedure containing the Update statement.

The string executes fine and uses parameters that are bound to controls in a details view (I know this is not best practice and it pains me having to work with data connections from the client side...! But I dont have time to re-write all the data connections for this and many pages just yet).

Anyway, I have just changed the UpdateCommand to a stored procedure that does the same thing and I just get the error

Input String was not in a correct format.

when I try to update on the page.

I can supply code if requested, but it is big & horrible so I am tentatively asking if anyone has any initial ideas? I will put a few small bits below though. I have been looking at the UpdateParameterCollection as I wonder if the parameter collection is getting cached anywhere - but cannot see anything.

I have controls bound to the DataSource items like so:

<EditItemTemplate>
    <asp:CheckBox ID="chkNonReview" runat="server" Checked='<%# Bind("NonReview") %>' />
</EditItemTemplate>

And the SqlDataSource has been changed from this...

<asp:SqlDataSource ID="dsEventDV" runat="server"
     ConnectionString="<%$ ConnectionStrings:MyConnString %>"
     DeleteCommand="DELETE FROM [I_TRAINEE_EVENTS] WHERE [EVENTID] = @EVENTID"
     InsertCommand="INSERT_TRAINEE_EVENTS_ED3"
                        InsertCommandType="StoredProcedure"
     OnInserted="DSEvent_Inserted"
     SelectCommand="Get_Candidate_Events_I3"
     SelectCommandType="StoredProcedure"
     UpdateCommand="UPDATE I_TRAINEE_EVENTS (etc...)"
.....

to this:

<asp:SqlDataSource ID="dsEventDV" runat="server"
     ConnectionString="<%$ ConnectionStrings:MyConnString %>"
     DeleteCommand="DELETE FROM [I_TRAINEE_EVENTS] WHERE [EVENTID] = @EVENTID"
     InsertCommand="INSERT_TRAINEE_EVENTS_ED3"
     InsertCommandType="StoredProcedure"
     OnInserted="DSEvent_Inserted"
     SelectCommand="Get_Candidate_Events_I3"
     SelectCommandType="StoredProcedure"
     UpdateCommand="UPDATE_TRAINEE_EVENTS"
     UpdateCommandType="StoredProcedure">
.....

With the new UpdateCommand values.

The update parameters:

<UpdateParameters>
    <asp:Parameter Name="EVENTID" Type="Int32"/>
    <asp:Parameter Name="EVENTTYPEID" Type="Int32"/>
    <asp:Parameter Name="EVENTDATE" Type="DateTime"/>
    <asp:Parameter Name="STAFFID" Type="Int32"/>
    <asp:Parameter Name="REVIEWNO" Type="Int32"/>
    <asp:Parameter Name="COMMENTS" Type="String"/>
    <asp:Parameter Name="DESTINYVERIFIED" Type="Int32"/>
    <asp:Parameter Name="DESTINYVERIFIEDBY" Type="Int32"/>
    <asp:Parameter Name="DESTINYVERIFIEDDATE" Type="DateTime"/>
    <asp:Parameter Name="REASONFORSUSPENSIONID" Type="Int32"/>
    <asp:Parameter Name="RETURNTOWORKDATE" Type="DateTime"/>
    <asp:Parameter Name="ContactDetailsUpdated" Type="Int32"/>
    <asp:Parameter Name="RETENTION_STATUS_ID" Type="Int32"/>
    <asp:Parameter Name="RETENTION_REASON_ID" Type="Int32"/>
    <asp:Parameter Name="NonReview" Type="Int32"/>
    <asp:Parameter Name="FalsifiedEventReason" Type="Int32"/>
    <asp:Parameter Name="SusReqReasonID" Type="Int32"/>
    <asp:Parameter Name="SusReqReturnDate" Type="DateTime"/>
</UpdateParameters>

The stored procedure declaration is as follows:

CREATE PROCEDURE [dbo].[UPDATE_TRAINEE_EVENTS]
    @EVENTID                int,
    @EVENTTYPEID            int,
    @EVENTDATE              datetime,
    @STAFFID                int,
    @REVIEWNO               int,
    @COMMENTS               varchar(2100),
    @DESTINYVERIFIED        int,
    @DESTINYVERIFIEDBY      int,
    @DESTINYVERIFIEDDATE    datetime,
    @REASONFORSUSPENSIONID  int,
    @RETURNTOWORKDATE       datetime,
    @ContactDetailsUpdated  int,
    @RETENTION_STATUS_ID    int,
    @RETENTION_REASON_ID    int,
    @NonReview              int,
    @FalsifiedEventReason   int,
    @SusReqReasonID         int,
    @SusReqReturnDate       datetime
AS
    ......

I have also run SQL Server Profiler against the session to see what was being passed to the database, however the error comes in before anything hits the database which appears to suggest the problem is within the ASP.NET side of things.

share|improve this question
    
Pls check your value and field datatype... – Kaushik Maheta Dec 2 '15 at 9:03
    
Sorry, I should have mentioned that I have gone over the datatypes numerous times to check they all match.. To the extent that I changed everything to Strings and Varchars in the SP)... I have even ensured that paramters are in the same order above as they are in the SP (as I know some data connection engines require this)... – CJH Dec 2 '15 at 9:17
    
Updated the code samples above to include full update parameters and the SP declaration. – CJH Dec 2 '15 at 9:33

Your <asp:Parameter Name="EVENTID" /> should have a datatype. I think it should be like this..

 <asp:Parameter Name="EVENTID" Type="Int32" />
share|improve this answer
    
Ah I copied in a bad sample - I had been doing a lot of playing around and missed it out on the snippet... Suffice to say that even with the datatype declaration you mentioned - I get the same problem... – CJH Dec 2 '15 at 9:19
    
I also stripped the parameters down to just one to see if there was one causing the problem, but just continue to get the same error... I have even tried setting NO Update Parameters and removing them from the SP... When I do this I get an error stating that the SP does not require parameters, but they are being passed... Even when I havent declared any. I therefore wonder if the control binding is effectively creating a parameter?? – CJH Dec 2 '15 at 9:21
    
Are you sure that the EVENTID has a value? Your error seems obvious. It's either its not an Integer or empty value. @ChrisHill – zzzzz Dec 2 '15 at 9:21
    
Please include your SP and your code behind in calling it @ChrisHill – zzzzz Dec 2 '15 at 9:23
    
Just updated the parameters to how it is currently set (the original parameters listed where from the original setup where the UpdateCommand was a string and worked... I have also added the declaration for the SP being contacted... Or not as the case may be!? Anything you could spot would be greatly appreciated - I have exhausted all my ideas! – CJH Dec 2 '15 at 9:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.