Solved

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

Posted on 2009-03-30
3
345 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now