CodeSmith Community
Your Code. Your Way. Faster!

[New Bie] Insert a new record to Nettiers

Latest post 01-23-2007 9:08 AM by sharan17a. 14 replies.
  • 12-08-2006 4:16 AM

    • ecadre
    • Top 100 Contributor
    • Joined on 10-16-2006
    • Posts 46
    • Points 1,230

    [New Bie] Insert a new record to Nettiers

    Hi, I am using newest nettiers 2, Visual Studio 2005, and Ms SQL server 2000.

    How to insert a new record with nettiers? I tried this code but failed :

    (Database for this code is taken from "NorthWind" sample database )

            Customers myCustomer = new Customers();
            myCustomer.CustomerID = "CUST";
            myCustomer.CompanyName = "CUST";
            CustomersService myServices = new CustomersService();
      
            if (myServices.Insert(myCustomer))
            {
                Label1.Text = "Success";
            }
            else
            {
                Label1.Text = "Failed";
            }
           

    Label1 always display "Failed". Something wrong with my code? (I am sure  no problem with database and its connection because I able to retrieve some record from customer table). Later, I tried this code, but also failed :

            Customers myCustomer = new Customers();
            myCustomer.CustomerID = "CUST";
            myCustomer.CompanyName = "CUST";
            CustomersService myServices = new CustomersService();       

            TList<Customers> myList = myServices.GetAll();
            myList.Add(myCustomer);
            myList.AcceptChanges();

            GridView1.DataSource = myList;
            GridView1.DataBind();

     Oddly, my GridView1 showing record of "mycustomer" but not in database.

     

    Thanks

     

    Alan 

     

    • Post Points: 35
  • 12-08-2006 4:30 AM In reply to

    • ecadre
    • Top 100 Contributor
    • Joined on 10-16-2006
    • Posts 46
    • Points 1,230

    Re: [New Bie] Insert a new record to Nettiers

    Ok, I tried this one too :

    DataRepository.CustomersProvider.Save(myCustomer); 

     ......and the result is : TIME OUT

    I immediately check my connection with this code (and it's working!) :

            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="customerdata">
                <Columns>
                    <asp:CommandField ShowEditButton="True" />
                    <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
                    <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
                    <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
                    <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
                </Columns>
            </asp:GridView>
            <data:CustomersDataSource ID="customerdata" runat="server"></data:CustomersDataSource>


     

    • Post Points: 35
  • 12-08-2006 4:44 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: [New Bie] Insert a new record to Nettiers

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 12-10-2006 8:23 PM In reply to

    • ecadre
    • Top 100 Contributor
    • Joined on 10-16-2006
    • Posts 46
    • Points 1,230

    Re: [New Bie] Insert a new record to Nettiers

    Oh my God, I add "Northwind.Web" to my web config.....and all is working. How can this happen?

        <httpModules>
          <!--
            Enable transaction-per-request pattern;  This module allows a single TransactionManager to be shared by
            all data access operations executed during a page request.  Used by the EntityDataSource control when
            the EntityDataSource.EnableTransaction property is set to True.
          -->

          <add name="EntityTransactionModule" type="Northwind.Web.Data.EntityTransactionModule, Northwind.Web"/>
        </httpModules>

    • Post Points: 35
  • 12-11-2006 2:05 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: [New Bie] Insert a new record to Nettiers

    You have to specify what assembly the type resides in.

    swin

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 12-12-2006 10:28 PM In reply to

    • ecadre
    • Top 100 Contributor
    • Joined on 10-16-2006
    • Posts 46
    • Points 1,230

    Re: [New Bie] Insert a new record to Nettiers

    Still not understand, but It's working now.

     Thanks
     

    • Post Points: 35
  • 12-13-2006 2:46 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: [New Bie] Insert a new record to Nettiers

    "type" is quite a common attribute in .Net config files (not just NetTiers) and what it usually expects is this format...

    type="namespace.mytype, assembly"

    where "namespace.mytype" is the type you're referencing and "assembly" is thw actual dll the type is located in.

    HTH

    swin

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 12-14-2006 2:40 AM In reply to

    • ecadre
    • Top 100 Contributor
    • Joined on 10-16-2006
    • Posts 46
    • Points 1,230

    Re: [New Bie] Insert a new record to Nettiers

    Thanks Mr. Swin, I got some knowledge on this.
    • Post Points: 5
  • 01-22-2007 2:18 PM In reply to

    Re: [New Bie] Insert a new record to Nettiers

    I'm also a newbie who wants to start by inserting something!  Newer than you I feel! 

    My question is, what is 'myServices' in your example?  I can get a handle into an insert statement - and cannot find 'services' in my entire solution.

    Hope you can help

    Steve

    • Post Points: 35
  • 01-22-2007 4:39 PM In reply to

    Re: [New Bie] Insert a new record to Nettiers

    Hi,

    It's a generation time option to generate a ComponentLayer, which could be a ServiceLayer or a DomainModel layer.

    http://wiki.nettiers.com/componentlayer
     


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 01-23-2007 4:51 AM In reply to

    Re: [New Bie] Insert a new record to Nettiers

    Brilliant - thanks for your reply, I'll try that today.

    Like to ask another question - why is it an option?  What is the 'default' way of communicating with the data layer if you don't select this option?

    Cheers.
    • Post Points: 35
  • 01-23-2007 5:02 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: [New Bie] Insert a new record to Nettiers

    DataRepository.MyEntityProvider.Save( myEntity )

    The service layer just adds extra functionality before calling the methods in the MyEntityProvider.

    Check out the DataRepository class in your Data project which provides access to the Providers via static properties.

    hth

    swin
     

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 01-23-2007 6:29 AM In reply to

    Re: [New Bie] Insert a new record to Nettiers

    Excellent - I now have a project generated with a service layer - I'm moving now!

    What is the best practice now - include the generated code into a new web project - or add a web project to the generated project?  And do I just add a reference to the services layer?

    Thanks,

    Steve

    • Post Points: 35
  • 01-23-2007 6:48 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 925
    • Points 34,785

    Re: [New Bie] Insert a new record to Nettiers

    I have several app's (web, services, gui etc etc) which all use the same NetTiers projects, so I created separate VS solutions for each of the app's and then just added the NetTiers projects to the solution where needed. Typically you would add all 4 layers (Data, Data.SqlClient, Entities and ServiceLayer) to each solution.  Additionally you might add the NetTiers web project if you're solution is a website.

    hth

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 01-23-2007 9:08 AM In reply to

    Re: [New Bie] Insert a new record to Nettiers

    Superb, I'm flying now - nettiers/codesmiths is amazing!

    Thanks

    Steve.
    • Post Points: 5
Page 1 of 1 (15 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems