Adding a dataset to vs2005 app_code directory

Discussion in 'ASP .Net' started by paul, Oct 11, 2005.

  1. paul

    paul Guest

    Hi,

    Im trying to add a dataset to the app_code directory using vs2005 \
    SQL2005 beta 2. When I run through the wizard I select the option to
    auto create new Stored Procedures (Select, update, delete, insert
    commands) after already specifying a very basic select command that
    consists of two fields.
    All procedures are created fine and i'm able to save the xsd file.

    Then I create a new gridview in which i use the xsd file object as my
    datasource.
    On execution of the gridview it binds fine and i can even click on the
    edit button, but when i update with new values the following error
    occurs:

    ObjectDataSource 'ObjectDataSource1' could not find a non-generic
    method 'NewUpdateCommand' that has parameters:

    This seems like a common problem so i'm sure it's not major. Anybody
    have any ideas?

    Thanks
     
    paul, Oct 11, 2005
    #1
    1. Advertisements

  2. Hi,
    You created a dataset and you created the stored procedures that will
    manipulate this dataset and this is all OK.
    But the error message reveals that you are using also ObjectDataSource,
    which requires having a method for each database operation that call the
    created stored procedures.

    Please take a look at this
    http://msdn2.microsoft.com/en-us/library/dx70zk47 for more information.

    Best regards,
    Mohamed Sharaf
    MEA Developer Support Center
    ITWorx on behalf Microsoft EMEA GTSC
    --------------------
    | From:
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | Subject: Adding a dataset to vs2005 app_code directory
    | Date: 11 Oct 2005 02:10:23 -0700
    | Organization: http://groups.google.com
    | Lines: 23
    | Message-ID: <>
    | NNTP-Posting-Host: 81.178.3.208
    | Mime-Version: 1.0
    | Content-Type: text/plain; charset="iso-8859-1"
    | X-Trace: posting.google.com 1129021829 32291 127.0.0.1 (11 Oct 2005
    09:10:29 GMT)
    | X-Complaints-To:
    | NNTP-Posting-Date: Tue, 11 Oct 2005 09:10:29 +0000 (UTC)
    | User-Agent: G2/0.2
    | X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
    Alexa Toolbar; .NET CLR 1.1.4322; .NET CLR 2.0.50215),gzip(gfe),gzip(gfe)
    | Complaints-To:
    | Injection-Info: o13g2000cwo.googlegroups.com; posting-host=81.178.3.208;
    | posting-account=nCGitg0AAAAvxAHS2Y-Y8auAS-g4JE-R
    | Path:
    TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fa
    stwebnet.it!tiscali!newsfeed1.ip.tiscali.net!news.glorb.com!postnews.google.
    com!o13g2000cwo.googlegroups.com!not-for-mail
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet:349885
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Hi,
    |
    | Im trying to add a dataset to the app_code directory using vs2005 \
    | SQL2005 beta 2. When I run through the wizard I select the option to
    | auto create new Stored Procedures (Select, update, delete, insert
    | commands) after already specifying a very basic select command that
    | consists of two fields.
    | All procedures are created fine and i'm able to save the xsd file.
    |
    | Then I create a new gridview in which i use the xsd file object as my
    | datasource.
    | On execution of the gridview it binds fine and i can even click on the
    | edit button, but when i update with new values the following error
    | occurs:
    |
    | ObjectDataSource 'ObjectDataSource1' could not find a non-generic
    | method 'NewUpdateCommand' that has parameters:
    |
    | This seems like a common problem so i'm sure it's not major. Anybody
    | have any ideas?
    |
    | Thanks
    |
    |
     
    Mohamed Sharaf, Oct 11, 2005
    #2
    1. Advertisements

  3. paul

    Guest Guest

    I'm going to assume that Mahamed hasn't actually done this and that you are
    in fact binding the objectdatasource to the dataset, and using the methods
    generated by the datatable to execute your updates, as this is the way to
    access datasets in .Net 2.0. Please correct me if this is not the case.

    This is in fact the result of one of two bugs in Beta 2 (which are fixed in
    the RC BTW). Even though you created these methods using the designer, and
    even though you have the parameters specified in the objectdatasource
    definition, it still wants to use very specific parameters and will require
    that you have a method that takes certain parameters. The direct database
    update methods generated do not meet this strucure. You can get around this
    by modifying your procedures and updating your datatable, by wrapping your
    dataset with a class that implements static (shared) methods to do the
    updates and using it as your source, or by changing the
    OldValuesParameterFormatString to be {0} (no old parameters essentially).
    Note that to use some of the objectdatasource features such as paging, you
    will be required to implement methods with specific parameters.

    The other bug is more complicated, but if this doesn't work I will be happy
    to explain it. Neither occur in the release candidate, so if you upgrade to
    it you should be fine.
     
    Guest, Oct 11, 2005
    #3
  4. paul

    paul Guest

    Thanks for the reply john. I've managed to do what you've said and I
    actually wrote those methods in there own class.
    The 'SELECT' method works fine but the minute I try and execute a
    'DELETE' or 'UPDATE' method it complains there is no value present.
    I started debugging this and yes it's true there was no parameter
    value, it was NULL.

    I'm trying to execute the following c# code:

    public void DeleteItem(string Item)
    {
    SqlConnection conn = new
    SqlConnection(ConfigurationManager.ConnectionStrings["ServerConnectionString"].ConnectionString);
    SqlCommand command = new SqlCommand("sp_DeleteItem", conn);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add("@Item", SqlDbType.VarChar).Value = Item;
    conn.Open();
    int rows = command.ExecuteNonQuery();
    conn.Close();
    }

    How do I pass the parameter value to the class method?
    My datasource for the gridview seems to be setup correctly:

    <asp:GridView ID="GridView1" runat="server"
    DataSourceID="ObjectDataSource1">
    <Columns>
    <asp:CommandField ShowDeleteButton="True" />
    </Columns>
    </asp:GridView>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    DeleteMethod="DeleteItem"
    SelectMethod="getItems" TypeName="Class1">
    <DeleteParameters>
    <asp:parameter Name="Item" Type="String" />
    </DeleteParameters>
    </asp:ObjectDataSource>

    Hope you can help.
    Thanks
     
    paul, Oct 13, 2005
    #4
  5. paul

    Guest Guest

    The key on your grid should match the parameter to the method exactly. If
    they do not, it will not know what to pass to the method. In beta2 VS will
    sometimes not set your data key.
     
    Guest, Oct 13, 2005
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.