Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating web page using masterpage.In my master page i have written code to bind data in datalist.datalist have pagelinks,so i am using inline code to bind data from database.I am using store procedure to select data.Now i am getting error in my code that: [System.Data.SqlClient.SqlException] = {"Procedure or function 'GetLinkName' expects parameter '@pagename', which was not supplied."}
My store procedure to select data is:
ALTER PROCEDURE [dbo].[GetLinkName]
@pagename nvarchar(20),
@pagelinks nvarchar(20)
AS
SELECT pagename,pagelinks FROM AdminLinks
My code to bind data is:
public void BindList()
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = sqlcon;
        cmd.CommandText = "GetLinkName";
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        MyList.DataSource = ds;
        MyList.DataBind();
    }

I am using Hyperlink code as:
<br />
<asp:hyperlink id="HyperLink1" runat="server" cssclass="left_links" navigateurl="<%# DataBinder.Eval(Container.DataItem, "pagename")%>" text="<%# DataBinder.Eval(Container.DataItem, "pagelinks") %>" xmlns:asp="#unknown"></asp:hyperlink><br />

i have tried to bind in both way without using "@pagelink" and "pagelink" also.
please help me where i am doing mistake.
Posted
Updated 8-Sep-10 2:29am
v3

It's quite obvious, your stored proc takes two parameters, @pagename and @pagelinks, which have not been supplied before the call to da.Fill.

Also, in your DataBind for the hyperlink the column name is pagename not @pagename.
 
Share this answer
 
Comments
fwr 8-Sep-10 8:32am    
thanks for your response sir.but thats my problem.how can i bind data in inline code from datatable first,then bindlist() should run.
[no name] 8-Sep-10 8:44am    
I'll try again. THE STORED PROC REQUIRES PARAMETERS YOU HAVE NOT SUPPLIED!!! Do you understand?
You need to add the parameters to execute SP.
Find the code sample below.
SqlCommand cmd = new SqlCommand();<br />
            cmd.Connection = sqlcon;<br />
            cmd.CommandText = "GetLinkName";<br />
            cmd.CommandType = CommandType.StoredProcedure;<br />
<br />
            #region Parameters<br />
            SqlParameter p = new SqlParameter();<br />
            p.ParameterName = "@pagename";<br />
            p.Value = "something"; // Specify parameter value<br />
            p.SqlDbType = SqlDbType.NVarChar;<br />
            cmd.Parameters.Add(p);<br />
<br />
            p = new SqlParameter();<br />
            p.ParameterName = "@pagelinks";<br />
            p.Value = "something"; // Specify parameter value<br />
            p.SqlDbType = SqlDbType.NVarChar;<br />
            cmd.Parameters.Add(p);            <br />
<br />
            #endregion<br />
<br />
            SqlDataAdapter da = new SqlDataAdapter(cmd);<br />
            DataSet ds = new DataSet();<br />
            da.Fill(ds);<br />
            MyList.DataSource = ds;<br />
            MyList.DataBind();
 
Share this answer
 
Comments
fwr 9-Sep-10 2:22am    
Thanks sir, i got it.Now its running.

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