Hi everyone, I'm working with the infamous Northwind database w/in SQL 2008. I'm working on the basic Insert, Update, Delete functions by way of LINQ to SQL. I currently have things working pretty well but I'm having issues with a table that isn't auto-incremented for its ID number.
I'm looking for the equivalent of the C# (I believe) .max method so I can search the table for the highest ID number and increment + 1. The count method isn't working
because if I use that and delete rows and its ID number is the same as the .count, then I will get a unique PK exception thrown.
Any help would be awesome, I've been going at this and search all day to no avail.
This is my Insert Class thus far
Code:Public Class InsertClass Sub insertsub(ByVal regiondescription As String) Dim insert As New RegionLinqSQLDataContext Dim newregion As New Region With _ {.RegionDescription = frmInsert.txtboxRegionDesc.Text, _ .RegionID = insert.Regions.Count + 2} insert.Regions.InsertOnSubmit(newregion) Try insert.SubmitChanges() DisplayRegions.Show() MessageBox.Show("Insert successful") Catch ex As Exception MessageBox.Show("Insert not successful") End Try End Sub End Class




Reply With Quote
