Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…

806 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