473,881 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting id of the record you just added

In normal asp i used
---------

objRS.Open "tbl_Nieuws ", objConn, 1, 3
objRS.AddNew

objRS.Fields("N _Datum") = FormatDateTime( Now(),2)
objRS.Fields("N _Title") = ReplaceHTML(Upl oad.Form("title "))
objRS.Fields("N _Intro") = ReplaceHTML(Upl oad.Form("intro "))
objRS.Fields("N _Body") = ReplaceHTML(Upl oad.Form("body" ))
objRS.Fields("N _UserID") = Upload.Form("id ")
objRS.Fields("N _Image") = file.Filename
objRS.Fields("N _Ip") = strIP
objRS.Fields("N _Deleted") = 0

objRS.Update
IntID = objRS("N_ID")
objRS.Close

---------
to get the id of the record i just added.
in asp.net i have this but i dont know how i can accomplish the same and
wanted to know if there
is some easyway for it.

-----------------

Dim myConnection As New SqlConnection(A ppSettings("Dat abaseCon"))
Dim strSQL As String = "insert into tbl_Users" & _
"(U_Usernam e, U_Password, U_Email, U_KlantenNR, U_Auth_Code,
U_ToegangsID, U_Registered_On , U_Posts, U_Last_Logged_I n, U_Banned,
U_Avatar, U_IP, U_Active, U_Deleted, U_MSN)" & _
"values('"& tbGebruikersNaa m.Text & "'," & _
"'"& tbWachtwoord.Te xt & "'," & _
"'"& tbEmailAdres.Te xt & "'," & _
""& strKlantenNR &"," & _
"'"& i & "'," & _
"1," & _
"'"& DateTime.Now.To String("MM'-'dd'-'yyyy HH':'mm':'ss") &"'," & _
"0," & _
"'"& DateTime.Now.To String("MM'-'dd'-'yyyy HH':'mm':'ss") &"'," & _
"0," & _
"'no_avatar.gif '," & _
"'"& strIP & "'," & _
"0," & _
"0," & _
"'"& strMSN & "')"

Dim MyCommand As New SqlCommand(strS QL, myConnection)
myConnection.Op en()
MyCommand.Execu teNonQuery()
myConnection.Cl ose()

--------------
i want the record of the record i just added to the tbl_Users. How 2? thats
the question.

thx in advance,

Richard
Nov 18 '05 #1
4 1739
please post this question in this newsgroup:
microsoft.publi c.dotnet.framew ork.adonet
(news://news.microsoft.com/microsoft....amework.adonet)

--
Hope this helps,
Zeeshan Mustafa, MCSD

"Richard" <ri*****@nospam .com> wrote in message
news:40******** **************@ newsreader.ewek a.nl...
In normal asp i used
---------

objRS.Open "tbl_Nieuws ", objConn, 1, 3
objRS.AddNew

objRS.Fields("N _Datum") = FormatDateTime( Now(),2)
objRS.Fields("N _Title") = ReplaceHTML(Upl oad.Form("title "))
objRS.Fields("N _Intro") = ReplaceHTML(Upl oad.Form("intro "))
objRS.Fields("N _Body") = ReplaceHTML(Upl oad.Form("body" ))
objRS.Fields("N _UserID") = Upload.Form("id ")
objRS.Fields("N _Image") = file.Filename
objRS.Fields("N _Ip") = strIP
objRS.Fields("N _Deleted") = 0

objRS.Update
IntID = objRS("N_ID")
objRS.Close

---------
to get the id of the record i just added.
in asp.net i have this but i dont know how i can accomplish the same and
wanted to know if there
is some easyway for it.

-----------------

Dim myConnection As New SqlConnection(A ppSettings("Dat abaseCon"))
Dim strSQL As String = "insert into tbl_Users" & _
"(U_Usernam e, U_Password, U_Email, U_KlantenNR, U_Auth_Code,
U_ToegangsID, U_Registered_On , U_Posts, U_Last_Logged_I n, U_Banned,
U_Avatar, U_IP, U_Active, U_Deleted, U_MSN)" & _
"values('"& tbGebruikersNaa m.Text & "'," & _
"'"& tbWachtwoord.Te xt & "'," & _
"'"& tbEmailAdres.Te xt & "'," & _
""& strKlantenNR &"," & _
"'"& i & "'," & _
"1," & _
"'"& DateTime.Now.To String("MM'-'dd'-'yyyy HH':'mm':'ss") &"'," & _
"0," & _
"'"& DateTime.Now.To String("MM'-'dd'-'yyyy HH':'mm':'ss") &"'," & _
"0," & _
"'no_avatar.gif '," & _
"'"& strIP & "'," & _
"0," & _
"0," & _
"'"& strMSN & "')"

Dim MyCommand As New SqlCommand(strS QL, myConnection)
myConnection.Op en()
MyCommand.Execu teNonQuery()
myConnection.Cl ose()

--------------
i want the record of the record i just added to the tbl_Users. How 2? thats the question.

thx in advance,

Richard


Nov 18 '05 #2
eeuh? Okay althrou i dont know why i cant ask the question here? its asp.net
as far i know.. :S

Richard

"M. Zeeshan Mustafa" <ze*****@no-spm.please.zees han.net> schreef in bericht
news:OE******** ******@tk2msftn gp13.phx.gbl...
please post this question in this newsgroup:
microsoft.publi c.dotnet.framew ork.adonet
(news://news.microsoft.com/microsoft....amework.adonet)

--
Hope this helps,
Zeeshan Mustafa, MCSD

"Richard" <ri*****@nospam .com> wrote in message
news:40******** **************@ newsreader.ewek a.nl...
In normal asp i used
---------

objRS.Open "tbl_Nieuws ", objConn, 1, 3
objRS.AddNew

objRS.Fields("N _Datum") = FormatDateTime( Now(),2)
objRS.Fields("N _Title") = ReplaceHTML(Upl oad.Form("title "))
objRS.Fields("N _Intro") = ReplaceHTML(Upl oad.Form("intro "))
objRS.Fields("N _Body") = ReplaceHTML(Upl oad.Form("body" ))
objRS.Fields("N _UserID") = Upload.Form("id ")
objRS.Fields("N _Image") = file.Filename
objRS.Fields("N _Ip") = strIP
objRS.Fields("N _Deleted") = 0

objRS.Update
IntID = objRS("N_ID")
objRS.Close

---------
to get the id of the record i just added.
in asp.net i have this but i dont know how i can accomplish the same and
wanted to know if there
is some easyway for it.

-----------------

Dim myConnection As New SqlConnection(A ppSettings("Dat abaseCon"))
Dim strSQL As String = "insert into tbl_Users" & _
"(U_Usernam e, U_Password, U_Email, U_KlantenNR, U_Auth_Code,
U_ToegangsID, U_Registered_On , U_Posts, U_Last_Logged_I n, U_Banned,
U_Avatar, U_IP, U_Active, U_Deleted, U_MSN)" & _
"values('"& tbGebruikersNaa m.Text & "'," & _
"'"& tbWachtwoord.Te xt & "'," & _
"'"& tbEmailAdres.Te xt & "'," & _
""& strKlantenNR &"," & _
"'"& i & "'," & _
"1," & _
"'"& DateTime.Now.To String("MM'-'dd'-'yyyy HH':'mm':'ss") &"'," & _ "0," & _
"'"& DateTime.Now.To String("MM'-'dd'-'yyyy HH':'mm':'ss") &"'," & _ "0," & _
"'no_avatar.gif '," & _
"'"& strIP & "'," & _
"0," & _
"0," & _
"'"& strMSN & "')"

Dim MyCommand As New SqlCommand(strS QL, myConnection)
myConnection.Op en()
MyCommand.Execu teNonQuery()
myConnection.Cl ose()

--------------
i want the record of the record i just added to the tbl_Users. How 2?

thats
the question.

thx in advance,

Richard


Nov 18 '05 #3
you are right Richard, but see your question is about database
(ado in fact) so if you ask this question in adonet ng, there you'd
find more helpers dedicated for ado.net help.. this is a general
practice, the more accurate place you post your question,
the more quickly/well you'll be answered.

good luck :-)

--
Hope this helps,
Zeeshan Mustafa, MCSD
"Richard" <ri*****@nospam .com> wrote in message
news:40******** **************@ newsreader.ewek a.nl...
eeuh? Okay althrou i dont know why i cant ask the question here? its asp.net as far i know.. :S

Richard

"M. Zeeshan Mustafa" <ze*****@no-spm.please.zees han.net> schreef in bericht news:OE******** ******@tk2msftn gp13.phx.gbl...
please post this question in this newsgroup:
microsoft.publi c.dotnet.framew ork.adonet
(news://news.microsoft.com/microsoft....amework.adonet)

--
Hope this helps,
Zeeshan Mustafa, MCSD

"Richard" <ri*****@nospam .com> wrote in message
news:40******** **************@ newsreader.ewek a.nl...
In normal asp i used
---------

objRS.Open "tbl_Nieuws ", objConn, 1, 3
objRS.AddNew

objRS.Fields("N _Datum") = FormatDateTime( Now(),2)
objRS.Fields("N _Title") = ReplaceHTML(Upl oad.Form("title "))
objRS.Fields("N _Intro") = ReplaceHTML(Upl oad.Form("intro "))
objRS.Fields("N _Body") = ReplaceHTML(Upl oad.Form("body" ))
objRS.Fields("N _UserID") = Upload.Form("id ")
objRS.Fields("N _Image") = file.Filename
objRS.Fields("N _Ip") = strIP
objRS.Fields("N _Deleted") = 0

objRS.Update
IntID = objRS("N_ID")
objRS.Close

---------
to get the id of the record i just added.
in asp.net i have this but i dont know how i can accomplish the same and wanted to know if there
is some easyway for it.

-----------------

Dim myConnection As New SqlConnection(A ppSettings("Dat abaseCon")) Dim strSQL As String = "insert into tbl_Users" & _
"(U_Usernam e, U_Password, U_Email, U_KlantenNR, U_Auth_Code,
U_ToegangsID, U_Registered_On , U_Posts, U_Last_Logged_I n, U_Banned,
U_Avatar, U_IP, U_Active, U_Deleted, U_MSN)" & _
"values('"& tbGebruikersNaa m.Text & "'," & _
"'"& tbWachtwoord.Te xt & "'," & _
"'"& tbEmailAdres.Te xt & "'," & _
""& strKlantenNR &"," & _
"'"& i & "'," & _
"1," & _
"'"& DateTime.Now.To String("MM'-'dd'-'yyyy HH':'mm':'ss") &"',"
&
_ "0," & _
"'"& DateTime.Now.To String("MM'-'dd'-'yyyy HH':'mm':'ss") &"',"
&
_ "0," & _
"'no_avatar.gif '," & _
"'"& strIP & "'," & _
"0," & _
"0," & _
"'"& strMSN & "')"

Dim MyCommand As New SqlCommand(strS QL, myConnection)
myConnection.Op en()
MyCommand.Execu teNonQuery()
myConnection.Cl ose()

--------------
i want the record of the record i just added to the tbl_Users. How 2?

thats
the question.

thx in advance,

Richard




Nov 18 '05 #4
Hi Richard,

As for the retrieving the new added record's identity problem. In ADO.NET,
if we use the DataSet and together with the DataAdapter component to manage
the data's insert, update , delete. For example, in vs.net , we create the
DataAdapter using the "DataAdapte r Configuration wizard", there is an
advanced option called "Refresh the DataSet" which indicate that the
DataAdpater will add a Select statement after Insert and Update statements
to retrieve identity column values, default values and other values
calculated by the database. You can try draging a DataAdapter in VS.NET to
have a look.

If you don't use DataSet and DataAdapter , just use simple SqlCommand
object to execute sqlstatement, I'm afraid, the only means to rerieve the
identity of the new added record is to execute a select query after the
insert statement to retrieve the identity.
IN addition, here are some former threads in the group discussing on the
similar problem:

http://groups.google.com/groups?hl=e...RYxGtBHA.2552%
40tkmsftngp04&r num=5&prev=/groups%3Fq%3Dad o.net%2Bget%2Bn ew%2Brecord%2Bi dent
ity%26ie%3DUTF-8%26hl%3Den

http://groups.google.com/groups?hl=e...b01c275c5%24f6
7a9130%2437ef2e cf%40TKMSFTNGXA 13&rnum=19&prev =/groups%3Fq%3Dad o.net%2Bget%2B
new%2Brecord%2B identity%26hl%3 Den%26lr%3D%26i e%3DUTF-8%26start%3D10% 26sa%3DN

Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2384
by: Tony Stoker | last post by:
I have a .Net web app that adds a record to a SQL database. After the user adds their record I want to have a link that will link them to their new record! The recordID is a AutoNumber in the SQL server... How do I return the recordID after I have added the record?
1
1665
by: Tony | last post by:
Thanks for writing back and don't laugh at what I am about to post I am new to this type of stuff....this is what I have tried and it isn't working(please note in the try section I was just trying to see if it was grabbing my variable or not any suggestions or hints would be greatly appreciated: ******** Private Sub AddArticle()
15
2985
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting it. Simple database: I want to have a user enter Supply Orders (just for tracking purposes) by Item. The user may also enter a new item - "new" is a combination of Item, PartNumber and Vendor - they could have the
2
1350
by: thomasp | last post by:
I am using the following code to add a record to an Access database. If I run the code and go to the database the code is there, but if as soon as I run the code I try to access the record with the SQL statement: strSQL = "SELECT Target_NO FROM " & strtablename & " WHERE ID = " & intMaxID, I don't get the record that I just added although it does have the highest ID number. Is the code just running faster than the database gets updated? ...
6
2751
by: AA Arens | last post by:
Hi, I have a database with 2 main forms. Contacts and companies. I share the base with two others via LAN. On the companies form I have buttons to navigate throught the records (>400). We are mostly handling let say 5 companies. Every time I have to navigate or choose the find record button to get the right company. I am looking fo a feature to have listed in a combo list the last 5 visited records ("recently visited records").
4
2000
by: nch1978 | last post by:
I am new to programming and am sorry if this post is in the wrong area. I have a listbox bound to a table and a datagrid bound to another one with a connection through xml. I can change the data within the grid, with the following through a button on a different tab page within the form, but it does not save changes to the database, just shows them on the datagrid until the program is closed: 'Temporary Datasets to store the inserted or...
10
12727
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be certain that MyVar will be set to the key-field value that was created when the Append query ran. Now, there are other ways to do it - I know - that will ensure you 'nab' the correct record. But I was wondering
2
1059
by: =?Utf-8?B?SmFtZXM=?= | last post by:
Hello all, I have this idea that might not work, our website is built by someone else and is a CMS website. There is a page with links to other websites and at the moment I have created a file for each link, the file is just a .html file that redirects to the actual website. My links on the page are directed to the relevant file then my webstats tell me how many times each file has been loaded, and therfore how many click throughs each...
1
1749
by: sparks | last post by:
I have always just got a count on records and put up a box at the top of the entry forms saying something like 1 of 500 and updating it as you got to 500 of 500. I have never thought of this as meaning anything just a reference. Now they are wanting it for lookups, even though I have lookup pulldowns based on other criteria.. Well we want to see rec 200 on the report and an easy way to go to record 200.
1
10812
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10400
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9552
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7108
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5780
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.