Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

update dataset, and get insert id vb.net

Posted on 2006-07-21
7
Medium Priority
?
335 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 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

824 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