Not getting ID from tables

Not getting ID from tables

PatricioFinkPatricioFink Posts: 27Questions: 12Answers: 0

Why i'm not getting the DB row ID from this request?:

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Try adding "ID" as a third parameter to the new Editor(...) constructor, while also keeping your new Field("ID"). The default Editor looks for is "id" and the case might be getting confused somewhere.

    Allan

  • PatricioFinkPatricioFink Posts: 27Questions: 12Answers: 0

    Nop, not workin. I even change the field name in the DB to "id" (lower case)



  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hmm - weird. Could you send me a dump of your DB table (just the structure will do - don't need the data)? I'll try to reproduce it here.

    Thanks,
    Allan

  • PatricioFinkPatricioFink Posts: 27Questions: 12Answers: 0

    USE XXX
    GO

    /****** Object: Table [dbo].[Clientes] Script Date: 11/3/2017 3:47:28 PM ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    CREATE TABLE [dbo].[Clientes](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar NULL,
    [Apellido] nvarchar NULL,
    [Direccion] nvarchar NULL,
    [Telefono] nvarchar NULL,
    [Email] nvarchar NULL,
    [Facebook] nvarchar NULL,
    [Twitter] nvarchar NULL,
    [Instagram] nvarchar NULL,
    [Comercio_ID] [int] NOT NULL,
    [CuentaCorriente_ID] [int] NULL,
    [FechaDeIngreso] [datetime] NOT NULL,
    CONSTRAINT [PK_Clientes] PRIMARY KEY CLUSTERED
    (
    [id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO

    ALTER TABLE [dbo].[Clientes] WITH CHECK ADD CONSTRAINT [FK_Clientes_Comercios] FOREIGN KEY([Comercio_ID])
    REFERENCES [dbo].[Comercios] ([ID])
    GO

    ALTER TABLE [dbo].[Clientes] CHECK CONSTRAINT [FK_Clientes_Comercios]
    GO

    ALTER TABLE [dbo].[Clientes] WITH CHECK ADD CONSTRAINT [FK_Clientes_CuentaCorrientes] FOREIGN KEY([CuentaCorriente_ID])
    REFERENCES [dbo].[CuentaCorrientes] ([ID])
    GO

    ALTER TABLE [dbo].[Clientes] CHECK CONSTRAINT [FK_Clientes_CuentaCorrientes]
    GO

    Like that?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    edited November 2017

    Perfect - thanks. I've just tried this locally:


    var response = new Editor(db, "Clientes") .Field(new Field("id")) .Field(new Field("Nombre")) .Field(new Field("Apellido")) .Field(new Field("Telefono")) .Field(new Field("Email")) .Field(new Field("Facebook")) .Process(request) .Data(); return Json(response);

    And I get this back from the server:

    {
      "draw": null,
      "data": [
        {
          "DT_RowId": "row_1",
          "id": "1",
          "Nombre": "1",
          "Apellido": "2",
          "Telefono": "5",
          "Email": "6",
          "Facebook": "7"
        }
      ],
    

    I put a single row into the table in the database with that data.

    This is using SQL Express 13.

    edit Can you show me the JSON you are getting back from the server?

    Allan

  • PatricioFinkPatricioFink Posts: 27Questions: 12Answers: 0

    You are right, i'm getting the ID from the DB, this is the reposnse:

    But i can not show that in the table, i think that is because the ID is (of course) read only, and i'm not telling that anywhere in the code, right??

    1.JPG 31.3K
    2.JPG 156K
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Do you get any error messages when you uncomment the data: 'id' line?

    Also, use new Field("id").Set(false) on the server-side to tell the C# code not to write any value to the database that was submitted by the client-side.

    Allan

This discussion has been closed.