Solved

update dataset, and get insert id vb.net

Posted on 2006-07-21
7
321 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
[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
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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