Solved

Dreamweaver VB.Net - Get current Identity number from SQL and increment by one

Posted on 2009-03-30
3
351 Views
Last Modified: 2012-05-06
Need to get the current sql identity number or any number within a table and increment by one.  I need this to be done during the OnLoad event of a form.  basically it will autogenerate an id number incremented by one everytime a form is loaded.  I am using Dreamweaver VB.Net.  I am also using SQL 2005 Server. Please, I need your help ASAP.  Thank You!!
0
Comment
Question by:kouts1
  • 3
3 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24028686
There might be a way but I am not familiar with it, but I always thought to get the id was possible after a insert.

Why cant you just create and maintain your own table? Just have one column in there which you read and update each time
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24028751
Here is a simple example which reads a table called tblNextID which has just the one column in it called NextID. Once it reads it, the value in that table is incremented.

Now this example uses MSAccess, you can just change the connection string to your database


        Dim nextId As String
        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\Web_EE\Big EE.mdb")

        conn.Open()

        Dim oleCmd As OleDbCommand

'Run the SQL to get the id
        oleCmd = New OleDbCommand("SELECT NextID FROM tblNextID", conn)
        nextId = oleCmd.ExecuteScalar().ToString()

        MsgBox("Next Available ID is " & nextId)

'Now increment that ID
        oleCmd.CommandText = "UPDATE tblNextID SET NextID = NextID + 1"
        oleCmd.ExecuteNonQuery()

'Close
        conn.Close()

        conn = Nothing
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24028765
the above is just quick example. I think you can use a data adapter to do it, saves you running queries I guess.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Example works but why do I need to click twice on button 4 48
"Emulate" TAB key when press Enter Key 3 48
edit .asp files 5 31
SSRS Deployment problem 5 66
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question