?
Solved

Error on inserting on aspx page with stored procedure

Posted on 2014-02-21
10
Medium Priority
?
280 Views
Last Modified: 2014-02-27
I have an aspx and aspx.vb(code behind page). I am trying to upload values from dropdown list field. I am using a stored procedure in SQL Server 2012. I can get values to upload correctly if I am using int values in the table and the stored procedure. However, when I try and upload varchar values to varchar fields in the table I get the error.....Conversion failed when converting the varchar value 'Weigh-in' to data type int.

Can anyone tell me what I need to change?

ASPX page code
<td>
                                <asp:DropDownList ID="staffid" runat="server" DataSourceID="StaffNames" DataTextField="staffmember" DataValueField="staffid">
                                    <asp:ListItem Value="home">1</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                            <td>
                                <asp:DropDownList ID="groupid" runat="server" DataSourceID="groupname" DataTextField="codedescr" DataValueField="codedescr">
                                </asp:DropDownList>
                            </td>
                            <td>
                                <asp:DropDownList ID="weekid" runat="server" DataSourceID="WeekNumber" DataTextField="codedescr" DataValueField="codedescr">
                                </asp:DropDownList>
                            </td>
                            <td>
                                <asp:DropDownList ID="pointsid" runat="server" DataSourceID="Pointsdesc" DataTextField="codedescr" DataValueField="codedescr">
                                </asp:DropDownList>
                            </td>
                            <td>
                                <asp:TextBox ID="points_standard" runat="server" Width="50px"></asp:TextBox>
                            </td>
                            <td>
                                <asp:TextBox ID="points_bonus" runat="server" Width="50px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                    </table>
                </td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Update Points" />

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Wellnes2014ConnectionStringowner %>" InsertCommand="UpdatePoints" InsertCommandType="StoredProcedure">
            <InsertParameters>
                <asp:FormParameter FormField="staffid" Name="staffid" Type="Int32" />
                <asp:FormParameter FormField="groupid" Name="groupid" Type="String" />
                <asp:FormParameter FormField="weekid" Name="weekid" Type="String" />
                <asp:FormParameter FormField="pointsid" Name="pointsid" Type="String" />
                <asp:FormParameter FormField="points_standard" Name="points_standard" Type="Int32" />
                <asp:FormParameter FormField="points_bonus" Name="points_bonus" Type="Int32" />
            </InsertParameters>
        </asp:SqlDataSource>

Code Behind
Partial Class _GroupA
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        SqlDataSource1.Insert()
        Response.Redirect("~/groupa.aspx")
    End Sub

   
End Class

Stored Procedure
PROCEDURE [dbo].[UpdatePoints]
      -- Add the parameters for the stored procedure here
      @staffid int,
      @groupid AS varchar(150),
      @weekid varchar(150),
      @pointsid varchar(150),
      @points_standard int,
      @points_bonus int

--BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      ---SET NOCOUNT ON;
      AS
    -- Insert statements for procedure here
      INSERT INTO Points
      VALUES (@staffid, @groupid, @weekid, @pointsid, @points_standard, @points_bonus)
--END
0
Comment
Question by:derrekdeveloper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
10 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39877536
The error refers to a field called 'weigh-in'
, does this column exist in the table Points?

Suggest in your stored procedure you specify your column names in the insert statement:

INSERT INTO Points (StaffId, GroupId, WeekId, PointsId, PointsStandard, PointsBonus)
      VALUES (@staffid, @groupid, @weekid, @pointsid, @points_standard, @points_bonus)

obviously making sure that the column names shown above match your column names in your points table.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39877578
I recommend you to print the parameter values before you call the sp and then try to see if it works with your procedure directly from query window. The sp looks straight forward but the mapping of the parameters in the asp code might give problems.
0
 

Author Comment

by:derrekdeveloper
ID: 39877785
Very good point. I did just that and it failed in the stored procedure so I will focus on the SQL.

USE [Wellnes2014]
GO

DECLARE      @return_value int

EXEC      @return_value = [dbo].[UpdatePoints]
            @staffid = 1123,
            @groupid = N'ee',
            @weekid = N'ee',
            @pointsid = N'ee',
            @points_standard = 345,
            @points_bonus = 3

SELECT      'Return Value' = @return_value

GO

**************************************************
Msg 245, Level 16, State 1, Procedure UpdatePoints, Line 34
Conversion failed when converting the varchar value 'ee' to data type int.
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39877807
Are you sure that your groupid, weekid, and pointsid columns are varchar it appears one of these are the problem during the update.
To track down which one you could give each a unique value rather than all 'ee' so you can find out which one is causing the problem
0
 
LVL 27

Accepted Solution

by:
Zberteoc earned 2000 total points
ID: 39877821
What is that 'ee' value? Another thing is that all the parameters that were assigned the 'ee' value are of carchar type even though they are IDs and the error is about converting 'ee' varchar to int. :


      @groupid AS varchar(150),
      @weekid varchar(150),
      @pointsid varchar(150),


I guess those 3 parameters have to be of type int, or at least one. Check the type in the Points  table and match the parameters type. After that make sure that the app assigns the right values to those parameters, instead of 'ee'.
0
 

Author Comment

by:derrekdeveloper
ID: 39877837
Zberteoc
That is exactly my point. There is no conversion to do. I am going to drop and rebuild the table and see what happens.
0
 

Author Comment

by:derrekdeveloper
ID: 39878010
I've requested that this question be closed as follows:

Accepted answer: 0 points for derrekdeveloper's comment #a39877837

for the following reason:

I dropped the table then recreated it. It is working now.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39878008
I don't understand, we got you on the right track, actually pointing to the solution, but no points? I think we are entitled after the time and effort we put in.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39878011
I don't understand, we got you on the right track, actually pointing to the solution, but no points? I think we are entitled after the time and effort we put in.
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question