?
Solved

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

Posted on 2009-03-30
3
Medium Priority
?
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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