Results 1 to 3 of 3

Thread: Partial Class and Retrieving Primary Key on Insert

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Question Partial Class and Retrieving Primary Key on Insert

    This is very strange to me. The code below will work perfectly fine in a Windows application but fails in an ASP.NET 2.0 application.

    Anybody else run into this and if so, any resolution?

    This is key because it is an easy way to retrieve the latest identity value from a newly inserted record.

    A little history. In both Windows and ASP I am accessing sql2005 using TableAdapters. I used a Partial class so that I don't have to risk losing my code in the autogenerated code behind files for the tableadapter.

    Code:
    '--My Partial Class
    Imports Microsoft.VisualBasic
    
    Namespace zzzTableAdapters
        Partial Public Class zzzTableAdapter
            Public AutoID As Integer
            Private Sub _adapter_RowUpdated(ByVal sender As Object, ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs) Handles _adapter.RowUpdated
                AutoID = e.Row.ItemArray(0).ToString '--Here the ID field is 0.
            End Sub
    
        End Class
    End Namespace

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Partial Class and Retrieving Primary Key on Insert

    An error without an error message?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: Partial Class and Retrieving Primary Key on Insert

    no duh! In asp.net the Id field is not incremented but in vb.net it is!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width