none
Chaging sqldatadapter to sqlcommand to use stored procedure RRS feed

  • Question

  • Hi a new developer here.

    What I'm trying to do is load data into a dataset using Repeater in Asp.net

    Here what i've done in the code behind

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    SqlConnection cnn = new SqlConnection("somedatabase");
    //do i need to use dataadapter?Can i use sqlcommand and use stored procedure
    //SqlCommand command = new SqlCommand("p_Release_sel", conn);
    //command.CommandType = CommandType.StoredProcedure;
    //SqlParameter parameter = new SqlParameter();

    SqlDataAdapter da = new SqlDataAdapter("select * from Release", cnn);
    DataSet ds = new DataSet();
    da.Fill
    Repeater1.DataSource = ds.Tables["ReleaseID"];
    Repeater1.DataBind();

    }
    }

    and my HTML code

    <form id="WebForm2" method="post" runat="server">
    <asp:Repeater id="Repeater1" runat="server">
    <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem,"au_id") %><br>
    </ItemTemplate>
    </asp:Repeater>
    </form>

    Is this the correct way for me to use Repeater?ie can we use stored procedure to call it

    There's an error "The IlistSource does not contain any data sources"


     

     

    Friday, September 3, 2010 8:21 AM

Answers

  • Based on your post it is not really clear if you have an issue with retrieving data or using Repeater control. If it is repeater then I would recommend posting your question in ASP.NET-related forums (http://forums.asp.net/).

    Yes, you can use stored procedure to retrieve data and your commented out code is correct except the part where you create parameters. If your stored procedure requires parameters then you need to instantiate parameters, add them to the collection of SqlCommand parameters and pass values. This link contains example how to call parameterized stored procedure

    http://support.microsoft.com/kb/310070

     


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by liurong luo Wednesday, September 8, 2010 9:05 AM
    Friday, September 3, 2010 10:25 AM
    Moderator