none
Auto generated Primary Key.. recordset.Update? RRS feed

  • Question

  • guess I just don't understand..... 

    following samples and what I could find. 

    i have a SQL database with an auto increment pKey field. 

    Dim mTableAdaptor As New ImagingDataSetTableAdapters.BladeTableAdapter
            Dim mDataSet As New ImagingataSet.pBladeDataTable
            mTableAdaptor.Fill(mDataSet)

    all OK?

     Dim mRecipRow As DataRow = mDataSet.NewRow()

    With mRecipRow
                    .Item("PARTNUMBER") = mPartNumber
                    .Item("BLADE WIDTH") = mBLADE_WIDTH
                    .Item("THICKNESS") = mTHICKNESS

    .Item("PKey")= ???? 

    End With

    If I put something in the PKey field that's already used I get errors

    If I leave it blank I get errors.. column ID doesn't allow nulls

    maybe not real clear what I want but it's been a long day and I'm going home for the day.. 

    any ideas where I went wrong..?

    jb.. 


    • Edited by jb 1010 Monday, September 26, 2016 6:05 PM
    Monday, September 26, 2016 5:55 PM

Answers

All replies

  • Hi jb 1010,

    >>any ideas where I went wrong..?

    Based on your description, PKey is an auto increment Primary Key, so we don't need to pass PKey value to database. please remove related line of code, like this:

    With mRecipRow .Item("PARTNUMBER") = mPartNumber .Item("BLADE WIDTH") = mBLADE_WIDTH .Item("THICKNESS") = mTHICKNESS

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, September 27, 2016 2:47 AM
    Moderator
  • yes, I've done that but still receive error:

    Dim mTableAdaptor As New ImagingDataSetTableAdapters.BladeTableAdapter
            Dim mDataSet As New ImagingataSet.pBladeDataTable
            mTableAdaptor.Fill(mDataSet)

    all OK?

     Dim mRecipRow As DataRow = mDataSet.NewRow()

    With mRecipRow
                    .Item("PARTNUMBER") = mPartNumber
                    .Item("BLADE WIDTH") = mBLADE_WIDTH
                    .Item("THICKNESS") = mTHICKNESS
           '.Item("PKey")= ???? 
    End With


    mDataSet.AddRecipBladeRow(mRecipRow) <<<< this is where exception kicks.... with Column "ID" does not allow nulls.

    mTableAdaptor.Update(mRecipRow)



    I've double checked the database 

    CREATE TABLE [dbo].[RecipBlade] (
        [Id]                    INT            IDENTITY (1, 1) NOT NULL,
        [PARTNUMBER]            NVARCHAR (255) NULL,
        [BLADE WIDTH]           DECIMAL (5, 4) NULL,
        [THICKNESS]             DECIMAL (5, 4) NULL,
        CONSTRAINT [PK_RecipBlade] PRIMARY KEY CLUSTERED ([Id] ASC)
    );


    One thing I don't understand is. If I do a 'preview data' in the designer or load the datagridview they both report 345 Rows, but there are 363 rows in the preview data 
    grid and if I view data in the SQL Server Object Explorer I can see there are 363 records.???

    Could this be what is causing the problem?

    If so how do I 'fix'.. 

    still working on learning 

    jb.. 

     
    Tuesday, September 27, 2016 12:02 PM
  • Well not sure why or how, but....

    it works now. I removed the problem table from the 'data source' object that was being used.

    saved all... closed VS Studio.. opened the project back up and linked back the 'data source' to the table.. 

    all  fine now.. 

    I'm slowly finding out just how disconnected the data source is from the actual database. 

    Wednesday, September 28, 2016 1:39 PM