Click here to Skip to main content
15,569,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
datalist.aspx
protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "ups_JoinRegistration3";
        //cmd.Parameters.Add("@UserID", SqlDbType.Int);
        cmd.Connection = con;
        con.Open();

        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        dlProfile.DataSource = dt;
        dlProfile.DataBind();

        cmd.Dispose();
        con.Close();


    }
    protected void dlProfile_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Details")
        {

            Label lb = new Label();
            lb = (Label)e.Item.FindControl("Label2");
            string ID = lb.Text;
            ////string UserId = "";
            //int id = Convert.ToInt32(Request.QueryString["en"].ToString()); 
           
            //string UserId = Convert.ToString(e.CommandArgument);

            Response.Redirect("ViewDetails.aspx?@ID=" + ID);


in datalist.aspx also
System.Data.SqlClient.SqlException: Procedure or Function 'ups_JoinRegistration3' expects parameter '@ID', which was not supplied.
this error


ViewDetails.aspx

SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int id = Convert.ToInt32(Request.QueryString["@ID"].ToString());
            //string id = Request.QueryString["en"].ToString();
           
            SqlCommand cmd = new SqlCommand("ups_JoinRegistration3", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@ID", SqlDbType.Int).Value = id;
            cmd.Connection = con;
            con.Open();
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            dlProfile.DataSource = dt;
            dlProfile.DataBind();
            cmd.Dispose();
            con.Close();
            
        }



ups_JoinRegistration3

SQL
ALTER PROCEDURE [dbo].[ups_JoinRegistration3]
(@ID int)
AS

BEGIN



select * from Registration where ID=@ID
END



Registration table
SQL
ID          int
UserId      int
FirstName   nvarchar(50)
MiddleName  nvarchar(50)
LastName    nvarchar(50)
DateOfBirth nvarchar(50)
Gender      nvarchar(50)
Email       nvarchar(50)
Occupation  nvarchar(50)
State       nvarchar(50)
City        nvarchar(50)
Nationality nvarchar(50)




Error in asp as well as in sp
System.Data.SqlClient.SqlException: Procedure or Function 'ups_JoinRegistration3' expects parameter '@ID', which was not supplied.



can any one solve and help me thanks
Posted
Updated 14-Dec-11 19:54pm
v3

Hi,

Its quite clear.

You are passing ID as parameter to your stored procedure so when you executing the SP it looks for ID

In your code behind you didn't mentioned any parameter(mentioned but commented). When it executes your command it will check for the paramter which is not available and will give you the error.

Pass the ID paramater to the stored procedure from code-behind.

Hope this helps
 
Share this answer
 
Comments
ythisbug 15-Dec-11 1:19am    
<asp:DataList ID="dlProfile" runat="server" RepeatColumns="2" OnItemCommand="dlProfile_ItemCommand"
Width="248px" Height="546px" DataKeyField="UserId">
<itemtemplate>
<table>

<tr>
<td colspan="2" rowspan="4">
<asp:ImageButton ID="ibtnImage" runat="server" CommandArgument='<%# Eval("ID") %>'
Height="100px" ImageUrl="~/App_Data/image/images.jpg" Width="100px" CommandName="Details" />
</td>

</tr>
<tr><td align="left" style="width:100px">
<asp:Label ID="Label11" runat="server" Text="Id:">
<td align="left" style="width: 100px">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("ID") %>'>
</td>
</td>
<td align="left" style="width: 100px">
<asp:Label ID="Label5" runat="server" Text="First Name:">
</td>
<td align="left" style="width: 100px">
<asp:Label ID="Label6" runat="server" Text='<%# Eval("FirstName") %>'>
</td>
</tr>
<tr>
<td align="left" style="width: 100px">
<asp:Label ID="Label7" runat="server" Text="Middle Name:">
</td>
<td align="left" style="width: 100px">
<asp:Label ID="Label8" runat="server" Text='<%# Eval("MiddleName") %>'>
</td>
</tr>
<tr>
<td style="width: 23px">
</td>
<td align="center" colspan="3">
</td>
</tr>
<tr>
<td align="center" colspan="4">
<asp:LinkButton ID="Details" runat="server" Font-Bold="True" CommandArgument='<%#Eval("UserId")%>' CommandName="Details" NavigateUrl="~/ViewDetails.aspx?Userid=10">View Details
<td style="width: 100px">
</td>
<td align="left" style="width: 100px">
</td>
<td align="left" style="width: 100px">
</td>
</tr>
</table>

<itemstyle horizontalalign="Left">
sriman.ch 15-Dec-11 1:44am    
Why do you posted your HTML code ?....Check whether you are getting ID or not ? In your datalist.aspx page load where you are assigning ID to SP ?
ythisbug 15-Dec-11 1:47am    
i tried bro its showing same error..
ythisbug 15-Dec-11 1:48am    
in sp its not executing..i think problem in sp??is it??
sriman.ch 15-Dec-11 1:58am    
have you tried exceuting your SP in sql server directly?
create PROCEDURE [dbo].[ups_JoinRegistration3]  AS 
BEGIN
 select * from Registration 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900