i am trying to do something like this but it gives me error that cannot convert int to string , even the field which i am accessing from db is int and i parsed it into int but why ? here is my code:

userId = (int)com.Parameters["@ReturnValueUserId"].Value;
SqlDataSource1.InsertParameters["@userId"] = userId;

actually i am trying to insert userId into INSERTCOMMAND of sqldatasource control on .aspx page .

InsertCommand="INSERT INTO [tblJobAdv] ([advtitle], [startingdate], [endingdate], [mediumofadv], [refid], [jbid], [advDetails], [userId]) VALUES (@advtitle, @startingdate, @endingdate, @mediumofadv, @refid, @jbid, @advDetails, @userId)" 

                <asp:Parameter Name="advtitle" Type="String" />
                <asp:Parameter DbType="Date" Name="startingdate" />
                <asp:Parameter DbType="Date" Name="endingdate" />
                <asp:Parameter Name="mediumofadv" Type="String" />
                <asp:Parameter Name="refid" Type="Int32" />          
                <asp:QueryStringParameter Name="jbid" QueryStringField="jbid" Type="Int32" />
                <asp:Parameter Name="advDetails" Type="String" />


when i use .toString() with userid that been assigned , then it works , after changing Db field from int to Varchar but i want it to accept int variable, why it isn't accepting, send 8 hours but no progres, :( help
using sql server 2008 + asp.net3.5 (c#)

Recommended Answers

All 2 Replies

use Convert.ToInt32("your value which you want to convert from string to int.");

hope it will work


you are not adding userid.
Please add

<asp:Parameter Name="userid" Type="Int32" />  
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.