Solved

update dataset, and get insert id vb.net

Posted on 2006-07-21
7
313 Views
Last Modified: 2012-05-05
I am using a blank dataset which I fill, then update in the database.
I was wonding if there was a way to figure out the "ID" column which is an insert id after the update.


        Dim myTest As DataSet = LoadBlankTest() 'this returns a dataset select * from tests where 1=0
        Dim drTest As DataRow = myTest.Tables(0).NewRow
        drTest("description") = testName
        drTest("offset") = offsetValue
        dataAdapter.Update(myTest) 'This works, but dataset does not contain the id number after this


    Public Function LoadBlankTest() As DataSet
        LoadBlankTest = getDataSet("SELECT * FROM Tests WHERE 1=0")
    End Function

    Public Function getDataSet(ByVal selectString As String) As DataSet
        Try
            Dim myData As New DataSet()
            Dim myConnection As New OleDb.OleDbConnection(connectionString)
            dataAdapter.SelectCommand = New OleDbCommand(selectString, myConnection)
            Dim CB As OleDbCommandBuilder
            CB = New OleDbCommandBuilder(dataAdapter)
            dataAdapter.UpdateCommand = CB.GetUpdateCommand()
            dataAdapter.Fill(myData)
            getDataSet = myData
        Catch ex As Exception
            MsgBox("Database Error")
            getDataSet = Nothing
        End Try
    End Function


0
Comment
Question by:jackjohnson44
  • 5
  • 2
7 Comments
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 17155201
use @@identity if you are using Access 2000 or later. Does not work with Access 97
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17155211
run SELECT @@IDENTITY FROM Tests
0
 

Author Comment

by:jackjohnson44
ID: 17155462
are you sure that will work?

I am not using an insert id, I am updating a dataset.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 35

Expert Comment

by:YZlat
ID: 17156421
so what are you trying to do? it's not very clear to me
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17156424
"a way to figure out the "ID" column which is an insert id after the update"?
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17178022
why C grade?
0
 

Author Comment

by:jackjohnson44
ID: 17178142
Sorry about that.

Since there was no clear cut answer and I didn't think it would help out anyone else, I gave the question a c.
When I do a search, I only try to look at  the 4 star answers.
I feel like anyone looking at this post would just be wasting their time.
It could be because of my vague question, I don't dispute that, but it is just cluttering the site.
I was grading that way more for the integrity of the knowledge base than for effort.

I was trying to get the dataset to hold the insert id which could be used in the code above.

"SELECT @@IDENTITY FROM Tests" does not necessarily return the insert id of what I am doing.
It gets the last insert id on the table, but not necessarily on the code above.
It is also database dependent.

It also doesn't allow me to use the dataset I currently have.

I would usually try to delete the question, because I think this site is a valuble resource.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 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