|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Getting AutoNum field from updated db table via data adapterI have a dataset that has an Orders table and an Order details table. There is a datarelation between the two, but the information inside the dataset isn't actual order history, it's orders that I'm about to receive, and the relationship built between the two tables isn't the actual Orders autonum field from the database but a data column I added myself with the autoincr attributes set (seed=-1 step=-1) What I'm trying to do is take that infomation, have the user select which products are being received with that order, and when they "commit" the information, I'd like the dataadapter to update the row (even if it's one row at a time) into the database and get the value of the autonum field that replaced the -1 or -2 that was in the dataset. Is this possible? If I can do that then it won't be a problem adding the details into the child table. Any assistance would be greatly appreicated. Thanks! Check out Bill Vaughn's Retrieving the Gozoutas article -
www.betav.com ->Articles -> MSDN. You basically need to use an output param or fire another select query. If you use the Configuration wizard to build the query once, you can see what it generates, it defaults to refreshing the dataset which tacks on a select statement at the end. "Rico" <r c o l l e n s @ h e m m i n g w a y . c o mREMOVE THIS PART IN CAPS> wrote in message news:4a_Rf.145791$H%4.34387@pd7tw2no... Show quote > Hello, > > I have a dataset that has an Orders table and an Order details table. > There is a datarelation between the two, but the information inside the > dataset isn't actual order history, it's orders that I'm about to receive, > and the relationship built between the two tables isn't the actual Orders > autonum field from the database but a data column I added myself with the > autoincr attributes set (seed=-1 step=-1) > > What I'm trying to do is take that infomation, have the user select which > products are being received with that order, and when they "commit" the > information, I'd like the dataadapter to update the row (even if it's one > row at a time) into the database and get the value of the autonum field > that replaced the -1 or -2 that was in the dataset. Is this possible? If > I can do that then it won't be a problem adding the details into the child > table. > > Any assistance would be greatly appreicated. > > Thanks! > Hi WG.
Thanks for the quick response. Unfortunately, I'm quite new to ADO.net, and building from scratch has always made more sense to me than using the wizards (the wizards just tend to confuse me more than I already am!) ;) I tried to use the configuration wizard anyway, and did see the "Parameters" collection with everything but the autonum field in it. The following is the command text "INSERT INTO Orders (tOrderName, wOrderDate) VALUES (?, ?)" if that makes any difference. If I undserstand correctly, are you suggesting I pass a unique value of some sort to the table and then query that back to get the new autonum value? Rick Show quote "W.G. Ryan - MVP" <WilliamRyan@nospam.gmail.com> wrote in message news:uBBh95GSGHA.4976@TK2MSFTNGP11.phx.gbl... > Check out Bill Vaughn's Retrieving the Gozoutas article - > www.betav.com ->Articles -> MSDN. > > You basically need to use an output param or fire another select query. If > you use the Configuration wizard to build the query once, you can see what > it generates, it defaults to refreshing the dataset which tacks on a > select statement at the end. > "Rico" <r c o l l e n s @ h e m m i n g w a y . c o mREMOVE THIS PART IN > CAPS> wrote in message news:4a_Rf.145791$H%4.34387@pd7tw2no... >> Hello, >> >> I have a dataset that has an Orders table and an Order details table. >> There is a datarelation between the two, but the information inside the >> dataset isn't actual order history, it's orders that I'm about to >> receive, and the relationship built between the two tables isn't the >> actual Orders autonum field from the database but a data column I added >> myself with the autoincr attributes set (seed=-1 step=-1) >> >> What I'm trying to do is take that infomation, have the user select which >> products are being received with that order, and when they "commit" the >> information, I'd like the dataadapter to update the row (even if it's one >> row at a time) into the database and get the value of the autonum field >> that replaced the -1 or -2 that was in the dataset. Is this possible? >> If I can do that then it won't be a problem adding the details into the >> child table. >> >> Any assistance would be greatly appreicated. >> >> Thanks! >> > > I just wound up creating a work around, by adding a GUID column to the
dataset, adding that to the database and reading that back to get the autonum. It bothers me having duplicate ID values, but what can you do. I like ADO.net with all the cool functionality it has, but I find it amazing that it lacks something that should be as easy as old technology (like DAO getting the new ID number). Hopefully it's on the ADO.net wish list. ;) Rick "Rico" <r c o l l e n s @ h e m m i n g w a y . c o mREMOVE THIS PART IN CAPS> wrote in message news:Er%Rf.144536$sa3.81716@pd7tw1no... Show quote > Hi WG. > > Thanks for the quick response. Unfortunately, I'm quite new to ADO.net, > and building from scratch has always made more sense to me than using the > wizards (the wizards just tend to confuse me more than I already am!) ;) > I tried to use the configuration wizard anyway, and did see the > "Parameters" collection with everything but the autonum field in it. The > following is the command text > > "INSERT INTO Orders > (tOrderName, wOrderDate) > VALUES (?, ?)" > > if that makes any difference. > > If I undserstand correctly, are you suggesting I pass a unique value of > some sort to the table and then query that back to get the new autonum > value? > > Rick > > > > > > > "W.G. Ryan - MVP" <WilliamRyan@nospam.gmail.com> wrote in message > news:uBBh95GSGHA.4976@TK2MSFTNGP11.phx.gbl... >> Check out Bill Vaughn's Retrieving the Gozoutas article - >> www.betav.com ->Articles -> MSDN. >> >> You basically need to use an output param or fire another select query. >> If you use the Configuration wizard to build the query once, you can see >> what it generates, it defaults to refreshing the dataset which tacks on a >> select statement at the end. >> "Rico" <r c o l l e n s @ h e m m i n g w a y . c o mREMOVE THIS PART IN >> CAPS> wrote in message news:4a_Rf.145791$H%4.34387@pd7tw2no... >>> Hello, >>> >>> I have a dataset that has an Orders table and an Order details table. >>> There is a datarelation between the two, but the information inside the >>> dataset isn't actual order history, it's orders that I'm about to >>> receive, and the relationship built between the two tables isn't the >>> actual Orders autonum field from the database but a data column I added >>> myself with the autoincr attributes set (seed=-1 step=-1) >>> >>> What I'm trying to do is take that infomation, have the user select >>> which products are being received with that order, and when they >>> "commit" the information, I'd like the dataadapter to update the row >>> (even if it's one row at a time) into the database and get the value of >>> the autonum field that replaced the -1 or -2 that was in the dataset. >>> Is this possible? If I can do that then it won't be a problem adding the >>> details into the child table. >>> >>> Any assistance would be greatly appreicated. >>> >>> Thanks! >>> >> >> > > |
|||||||||||||||||||||||