Solved

update dataset, and get insert id vb.net

Posted on 2006-07-21
7
308 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
Comment Utility
use @@identity if you are using Access 2000 or later. Does not work with Access 97
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
run SELECT @@IDENTITY FROM Tests
0
 

Author Comment

by:jackjohnson44
Comment Utility
are you sure that will work?

I am not using an insert id, I am updating a dataset.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 35

Expert Comment

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

Expert Comment

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

Expert Comment

by:YZlat
Comment Utility
why C grade?
0
 

Author Comment

by:jackjohnson44
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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