Solved

update dataset, and get insert id vb.net

Posted on 2006-07-21
7
312 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

785 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