Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Reset Identity Counter


In SQL Server I have a column setup as Identity. Through testing this value has grown to a huge number. I would like to set this back to 1 when I move the database to production. Any ideas on how to do this?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Reset Identity Seed On Runtime
Is there any way to reset the Identity Seed of a autonumber column for a table within the VB.NET code? The reason for this is because I have to upload an input file every day which contains over 25,000 records. Everytime I upload the file, I have to delete all the records first.

Reset Counter
I'm having a little truble with resetting a counter to 0, in a loop I've got

Counter = WorksheetFunction.CountIf(.Range(....

the problem is that I would like to reset the counter to 0 at the beginning of the loop, but counter = 0 doesn't work!

Thanks in advance for your help

Reset Counter For Lines
I have a textbox holding multiple pages of text. I want to display the number of pages of text on the label. Each line is setup to be 90 characters long. The counter needs to be reset to 0 when len(text1,text) gets to 90. But I have been unable to get it working.

My code is like this:

If len(text1.text)=90 then
Counter=counter+1
Len(text1.text)=0
End if

The problem is that Len(text1.text) does not reset to 0. If Len(text1.text) does not reset, then the counter does not count correctly. How do I setup a counter to count as the Len function returns 90 characters each time. Along with that I need to count count Carriage returns, too, but that will come alter when I get this count correctly. Any help will be appreciated.

Thank you.

Reset Counter Value On CmdClick
I have this code:

Private Sub cmdSTOPRUN_Click(Index As Integer)
'LOAD FINISH TIME INTO CURRENT RUN DATA
Static cnt As Integer
If cnt = 0 Then
lblDRFT(1).Caption = Time
ElseIf cnt = 1 Then
lblDRFT(2).Caption = Time
ElseIf cnt = 2 Then
lblDRFT(3).Caption = Time
ElseIf cnt = 3 Then
lblDRFT(4).Caption = Time
ElseIf cnt = 4 Then
lblDRFT(5).Caption = Time
ElseIf cnt = 5 Then
lblDRFT(6).Caption = Time
ElseIf cnt = 6 Then
lblDRFT(7).Caption = Time
ElseIf cnt = 7 Then
lblDRFT(8).Caption = Time
ElseIf cnt = 8 Then
lblDRFT(9).Caption = Time
ElseIf cnt = 9 Then
lblDRFT(10).Caption = Time
End If
cnt = cnt + 1
End Sub

AND:

'VARIABLES ARE DECLARED
Dim Count As Integer
Dim SumTotals As Integer
Dim i As Integer
'TIMER IS USED TO REFRESH VALUES AND RESETS VALUES AT RUNTIME START
If tmrDREFRESH.Interval = 100 Then
Count = "0"
SumTotals = "0"
End If
'VALUES THAT WILL BE ACCUMULATED TO THE DAYSHIFT AVERAGE PRODUCED TOTAL
'VARIABLE "i" IS GIVEN A RANGE OF 1 TO 10 AS THERE ARE 10 RUNS TO BE DISPLAYED
For i = 1 To 10
'IF ANY OF THESE LABELES (1 TO 10) ARE GREATER THAN 0, THEN THE
'COUNTER INCREMENTS 1. THEN THE VARIABLE "SUM TOTALS" IS EQUAL TO ITSELF +
'THE VARIABLE VALUE
If Val(lblDAP(i)) > 0 Then
Count = Count + 1
SumTotals = SumTotals + Val(lblDAP(i))
End If
Next i
If SumTotals Or Count > 0 Then
lblDAPTOT(11).Caption = (SumTotals / Count) 1
End If


Upon clicking cmdReset all the values become blank along with others hence resetting the values in my form. I would now like to be able to load these values consecutively again starting at lblDRFT(1). There are 2 counters involved in seperate private subs cnt and Count. The reset command button is located in the same form as the counters. Would I possibly need a Public Sub with the reset click declaration to accomplish this? Is there such a thing as "global commands" that can executed to affect any form within the application?

Sorry but I have to learn somewhere!

D.

How Do I Reset A Simple Counter????
Hello All
I have a small problem again, my program writes to two text files & does this kind of itemised numbering...If you press enter 4 times it increments a counter once...so this way, if my first item is this code 00001 & so the fifth item will have 00002. Thats just the way it works! Now I have a button called 'back' in the form. And what I want is when back is clicked, the text file is read & then a character is appended to it, which works as well...then I close the handles Close #1 & Close #2...then I unload the form & load the main menu. But if I go back into itemization again, the counter starts from where I left it...for example if I itemised till 00002, it will start from 00003 while I want it to start from 00000 again...any help!!! Please help. I tried to set the counter back to 0000 on click event of back but does not work...;-(
Thanks

Reset Counter Depending On Date
I need to run a sub routine that checks a cell in the excel spreadsheet that will contain the date that the LAST specific record was enetered. When the Date changes I need to reset the counter to 1.



Edited by - Unipowered on 1/14/2004 6:36:04 AM

How Do I Reset A Simple Counter? -Sorry For The Last Similar Post.
Hello All
I have a small problem again, my program writes to two text files & does this kind of itemised numbering...If you press enter 4 times it increments a counter once...so this way, if my first item is this code 00001 & so the fifth item will have 00002. Thats just the way it works! Now I have a button called 'back' in the form. And what I want is when back is clicked, the text file is read & then a character is appended to it, which works as well...then I close the handles Close #1 & Close #2...then I unload the form & load the main menu. But if I go back into itemization again, the counter starts from where I left it...for example if I itemised till 00002, it will start from 00003 while I want it to start from 00000 again...any help!!! Please help. I tried to set the counter back to 0000 on click event of back but does not work...;-(
Thanks
The code is here:

Private Sub cmdB_Click()
MsgBox "Go back and lose any information entered?", vbYesNo, "Check Access"
If vbYes Then
Close #1
Close #2
Call UnloadAll
Load frmMain
frmMain.Hide
On Error Resume Next
Open MyFile For Input As #1
TheFile = Input(LOF(1), 1)
Close #1
LastChar = Right(TheFile, 1)
If LastChar <> "" Then
TheFile = Left(TheFile, Len(TheFile) - 1)
TheFile = TheFile & "" & "STOP" & ""
Kill MyFile
Open MyFile For Append As #1
Print #1, TheFile
counter = 0
Close #1
End If
End If
frmMain.Show
End Sub

Help Needed - How To Reset The The Counter Generate By Command Button
Dear all,

I am relatively new in visual basic programming, and am currently have the above problem.

I am not sure how i can reset the counter back to 0 if the value of x = 5.

What i want to achieve is, with each click on the "command" button, the counter start increasing by 1 per click.
But when the value of x becomes 5, the counter reset back to 0.
When the command button is clicked, again it starts the counter again from 0.

Private Sub Command_Click()
Static counter as integer
counter = counter + 1
End Sub

Please advise me on how do i include the reset fixture in this script. Thank you

Get @@Identity
Hi,

This is my first post here, and I know my question has been asked before, however after reading all of the suggestions, I'm still stuck!

I have written an Add(...) method for inserting a record into SQLServer 2000. The class is in an ActiveX DLL and will be used from an ASP page. All I want to do is to get the @@Identity from the record added, but for some reason, I get the following error: "ADODB.Errors (0x800A0CC1) Item cannot be found in the collection corresponding to the requested name or ordinal."

I know this can be done using a recordset, however I'd rather not if possible. Could anyone correct my VB code below? Thanks!

The stored procedure will be something like this:

CREATE PROCEDURE [dbo].[spProductsInsert]
(
@ProductName nvarchar (50),
@ProductID int OUTPUT
)
AS
INSERT INTO Products
(
ProductName
)
VALUES
(
@ProductName
)
SELECT
@ProductID = @@Identity
GO

...And the VB I have at the moment is as follows:

Code:
Public Function Add(ByVal objProduct As Product) As Integer

' error handling
On Error GoTo ErrorHandler

' for new primary key value
Dim newID As Integer

' connection and command objects (early binding)
Dim objCmd As ADODB.Command
Set objCmd = New ADODB.Command
Dim objCon As ADODB.Connection
Set objCon = New ADODB.Connection

' connect to the database
objCon.ConnectionString = m_ConnectionString
objCon.Open

' set command properties
With objCmd
.CommandText = "spProductsInsert"
.CommandType = adCmdStoredProc
.ActiveConnection = objCon
' RETURN_VALUE for any error output
.Parameters.Append .CreateParameter("RETURN_VALUE", _
adInteger, adParamReturnValue, 0)
.Parameters.Append .CreateParameter("@ProductName", _
adVarChar, adParamInput, 50, objProduct.ProductName)
.Parameters.Append .CreateParameter("@ProductID", _
adInteger, adParamOutput, 4)
.Execute , , adExecuteNoRecords

' get the primary key value
newID = CInt(.Parameters("ProductID").Value)
End With

' return the primary key value
Add = newID

' tidy up
objCon.Close
Set objCon = Nothing
Set objCmd = Nothing

Exit Function

ErrorHandler:
Err.Raise objCon.Errors.Item(0).Number, _
objCon.Errors.Item(0).Source, _
objCon.Errors.Item(0).Description
Set objCon = Nothing
Set objCmd = Nothing

End Function

Identity
Hi people! I have a Table (in MSSQL 8.0) wich primary key is an IDENTITY. I want to insert a record in that table and get the identity´s value cause it is a foreign key for several tables i have to insert records to..
Wich is the best wayto do it? I do a SQL query using MAX but i want to know if Is it possible to overlap inserts and get the wrong identity!
Thanks in advanced and sorry my english!
Bye!

Identity
Hi people! i have this:


Code:
Dim Rst as new adodb.recordset, i as Integer
Rst.Open "select top 1 * from Table1", Cndb

For i=0 to Rst.Fields.Count -1
Select Case Rst.Fields(i).Type
Case adNumeric, adCurrency, adDecimal, adDouble, _
adSingle, adBigInt, adBinary, adGUID, adInteger, adSmallInt, _
adUnsignedBigInt, adUnsignedInt, adUnsignedSmallInt, _
adUnsignedTinyInt, adVarBinary

msgbox "this is a number!"

Case adDate, adDBDate, adDBTime, adDBTimeStamp
msgbox "this is date!"

Case adBoolean
msgbox "this is boolean!"

Case Else
msgbox "this is text!"
End Select
next i
This function is to loop through a recordset's fields and print wich type is the field.
I just want to know how to know that a field is identity!
Thanks in advance and sorry my english!

Identity
hi people!
I want to know wich is the best way to retrieve the recently value from a identity field!


Code:
cndb.Execute "INSERT INTO TABLE1 (fName,fSurname) VALUES ('Carol','Vilmar');"
I want it to return me the value contained in an identity field in that table!

Thanks in advance and sorry my english!
(Further information: vb6 & MS SQL SERVER)

Exe Identity
Hey, i need a way to get the unique identity of an exe file. I can't use exe name, cause it can be changed. Is there a way to do this?

Thanks

BCP And Identity
GentleMen/Women: (Hope everyone was able to get some rest
in spite of these haunting images from TV! May this day find u all well!)

Q. When one BCPs a file into a table (SQL SERVER) is the
data entered into the table in the same sequence as it is
in the file

if not, is there a way to do that and possibly set an identity
field on that table so that (after I do the stuff that I need
to do with the data) I can put it back to the file in the
original sequence?

The original file is not sorted in a any specific way...


Thanks in advance...

ADO And @@identity (SQL 7)
Hi all long time no see. I'm using ADO to insert a new record (SQL server 7) using .AddNew().

The question is: How do I get the auto-inserted identity value of that inserted row? I can't use a stored proc because of the nature of the binary data I'm storing - I need to use GetChunk and all that.

I would be very grateful for any help any of you gurus can offer (I'm told flattery will get a man anywhere)

Thanks all,

Toot

Need Identity Help
Hi,

I have one question.i have to tables in sql server in one table i have setup the identity with primary key and in other table i want to use identity values to relashionship i know how to do.in sql server but i dont know how to do in vb6 please can anybody help me.

Quote: Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Hotel Management"
cn.Open

Set rs = New ADODB.Recordset

SqlQry = "CustomerDetails "
With rs
.Open SqlQry, cn, adOpenKeyset, adLockPessimistic, adCmdTable



.AddNew
rs!Name = txtName.Text
rs!LastName = txtLastName.Text
rs!Gender = CmbGender.Text
rs!Address1 = txtAddress1.Text
rs!Address2 = txtAddress2.Text
rs!City = txtCity.Text
rs!State = txtState.Text
rs!Country = txtCountry
rs!Email = txtEmail.Text
rs!phone = txtPhone.Text
rs!IdentityProof = txtIdentity.Text
rs!ReasonVisit = txtReason.Text
rs.Update
txtName.Text = ""
txtLastName.Text = ""
CmbGender.Text = ""
txtAddress1.Text = ""
txtAddress2.Text = ""
txtCity.Text = ""
txtState.Text = ""
txtCountry.Text = ""
txtReason.Text = ""
txtEmail.Text = ""
txtPhone.Text = "'"
txtIdentity.Text = ""

End With




Set rs = New ADODB.Recordset
SqlQry = "RoomDetail "
With rs
.Open SqlQry, cn, adOpenKeyset, adLockPessimistic, adCmdTable

.AddNew

rs!RoomNumber = txtRoomNumber
rs!RoomType = CmbRoomType.Text
rs!BedType = CmbBedType.Text
rs!Advance = txtAdvance.Text
rs!RentPerDay = txtRent.Text
rs!CheckinDate = txtCheckinDate.Text
rs.Update
End With

SQL Identity
Hey guys! I have a very urgent project but I have a hard time solving it. I need your help. Hope you can help me. This is my SQL query...

TRUNCATE Table Delivery
INSERT INTO Delivery(Reference, Notes, RevisionID, Address, Instructions, CustomerID)
SELECT [SalesOrder].[Customer Reference], [SalesOrder].Notes, [SalesOrder].RevisionID, [SalesOrder].[Delivery Address],
       [SalesOrder].[Special Instructions], [SalesOrder].[Customer ID]
FROM [SalesOrder] INNER JOIN ([SOLine] INNER JOIN [DN Lines] ON [SOLine].[SO Line ID] = [DN Lines].[SO Line ID])
       ON [SalesOrder].[SO ID] = [SOLine].[SO ID] ORDER BY [SOLine].[SO Line ID], [DN Lines].[DN Seq], [SOLine].[SO ID]

I need to get the values of the Identity Column in the Delivery Table called "DeliveryID" and put it in the "DeliveryID" field of [DN Lines] Table. How do I do this without going thru the values of the Delivery table row by row and save it to [DN Lines]? Note: There are 20,000 records in the Delivery table that's why I used the above statements inorder to speed up the process.
Anyone here who's kind enough to help me? Your help will be pretty much appreciated. Thanks.

Identity
How to set the table to allow identiy insert on
eg "set identity_insert table on" using
ADO before calling the addnew method.

thanks.

Help!! {Identity Insert}
I keep getting this error: "Cannot insert explicit value into table when IDENTITY_INSERT set to off. I think I'm forgetting to do something here but I can't put my finger on it. I get the error on Submit, here's my code:


Code:
Private Sub cmdSubmit_Click()

'check drop down box

If DropDownBox.ItemData _
(DropDownBox.ListIndex) = 0 Then


MsgBox _
"Select ", _
vbOKOnly

GoTo Subexit:
End If

' Insert statement

strSQLUpdate = _
"up_Update " & _
intSelectionID & "," & _
DropDownBox.ItemData _
(DropDownBox.ListIndex) & "," & _
intUsedID


' Insert the Transaction

Set rsSubmit = global_Conn.Execute(strSQLUpdate) **<it highlights this.


' Clear and form1 grid

PopulateGrid _
strSQLGrid, _
"column 1:", _
"intMainID", _
"strMainName", _
"No Records", _
form1.Grid

cmdSubmit.Enabled = False

DropDownBox.ListIndex = 0
DropDownBox.Enabled = False


' Close the Form


Unload Me

Subexit:
End Sub

Identity From Name From Class
i have a class with some methods, and form that call this method.

how can i know from the class, which form call this method ?

thanks,

How To Get The Identity Primary Key Value?
I have a table (tblArticleGroup) with a automatic increasing primary key (ArticleGroupID). I'm using a datatable to insert a new row in the table. Then I want to know the generated ArticleGroupID, but I haven't found a solution.

I'm using SQL Server 7.0

I checked on google and found a good example in C##. I translated it to vb.net (see below), but it doesn't work, because ArticleGroupID = 0 all the time. Can anyone see what's wrong with the code:


Dim conn As New SqlConnection(myConnectionString)
Dim da As New SqlClient.SqlDataAdapter("Select * from tblArticleGroup", conn)

da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim builder As New SqlClient.SqlCommandBuilder(da)
Dim Command As SqlCommand
Command = builder.GetInsertCommand()
Command.CommandText += " ; select @@IDENTITY as ArticleGroupID"
Dim dt As New DataTable()
da.FillSchema(dt, SchemaType.Source)

conn.Open()
dt.Clear()

Dim row As DataRow
row = dt.NewRow()
row("ChargeCodeSearchStr") = ""
row("Name") = "Testgroup"
row("IsTemporary") = True
dt.Rows.Add(row)

da.Update(dt)
dt.AcceptChanges()
MsgBox(row("ArticleGroupID")) 'This returns "0" all the time!!!
conn.Close()

Insert Identity
I have the following code, which when pasted into SQL Server Enterprise manager works fine.

SET IDENTITY_INSERT [Category] ON
INSERT INTO Category
(CategoryRef, Category)
VALUES (13, 'Chalet')

It forces in the autonumber identity of 13 into my table. great stuff. However, in my VB Code, some of the tables that I am pointing the code to, works fine too via a .EXECUTE command, but there are a couple that just won't let me do it and they come back with

identity insert is already ON, cannot set blah blah blah.

Any ideas of getting around this? (I have checked my spelling of table/field names etc.. and they're ok.)

How To Retrieve Identity?
Hi,

I have a identity column,

how i can get the value of this column after insert?

using visual basic and sql server
Thanks

Next Identity On A SQL TABLE
I can get the identity on a table with @@identity but i have to save the register first. But if i want to get that number before i save the information?

The Select @@identity
I had never used this before.
I want to get the next identity from a Table. Is this correct?
How do i have the result?

Function GetIdentityFromTable(sTable) As Integer
sqlstring = "Select @@Identity From " & sTable
Dim RsIdentity As ADODB.Recordset
Set RsIdentity = New ADODB.Recordset
RsIdentity.Open sqlstring, cn
End Function

Identity Field
When You use identity field (sql server):
a) If the Number is generate when you say: ADDNEW to the Table, how can i work with that value if i need before?

I mean, i need that value because has to be saved on another table. This mean that i have to save the HEADER first and then work with the detail?

Getting Identity Value In Access
I have a table in a MS Access database. The table has a primary column which is AutoNumber type. When I insert a row into this table the primary value will be added automatically to this row. I know in SQL Server, I can use 'Select @@identity' to get this primary value. Does anyone know how to do it in Access?

Thanks for you help,

IDENTITY COLUMN IN DB2
I want to create a identity column in DB2 that starts at 30001 and increments by one. I have done this easily in SQL7 but have not had the same luck in DB2. Heres what I have for SQL7 that works fine.

CREATE TABLE [TABLENAME](
[FIELDNAME] [INT] IDENTITY (300001, 1) NOT NULL,


anyone tell me how to get this to work in DB2?

thanks,
eye!

ADO And Identity Columns
Hi all,

I'm working on a database in SQL Server, and I want to set the identity field in code for certain columns. I can't seem to find how to do this using an ADOX object. Is there a way to do this using ADOX (and if so, how?), or do I need to use a different data access method to do this?

Thanks!

@@IDENTITY Equivalent In VBA
Hello,

Does anyone know of a VBA function that returns the id of a NEW record added in a recordset as soon as it has been added ?

It can be done using @@IDENTITY in a 'Stored Procedure'  but i need to use it in VBA.

Thanks


Identity On MS Access
My sql script look like this
create table ENVIO
(
    ID           Integer                 not null,
    CLAVE_REM    Integer                 not null,
    CLAVE_DES    Integer                 not null,
    FECHA        DateTime                not null    ,
    GUIA         Integer                 null    ,
    AUTORIZO     Text(30)                not null,
    DEPTO        Text(30)                not null    ,
    PAGA         Text(30)                not null    ,
    DESCRIPCION  Memo                    null
);

I need the field ID be autonumber type, I know that SQL has IDENTITY but in MS Access the only thing that I get is an error.

create table ENVIO
(
    ID           Integer     IDENTITY    not null,
    CLAVE_REM    Integer                 not null,
    CLAVE_DES    Integer                 not null,
    FECHA        DateTime                not null    ,
    GUIA         Integer                 null    ,
    AUTORIZO     Text(30)                not null,
    DEPTO        Text(30)                not null    ,
    PAGA         Text(30)                not null    ,
    DESCRIPCION  Memo                    null
);

Does any one know how to create a Auntonumber field with a SQL script???

Can Anyone Explain How To Use @@IDENTITY?????
I've spent days trying to find the answer to a simple question and after reading a gazillion different answers, I'm totally confused.

I'm using a form to add records to an Access 2002 database using an ADODB connection. I was able to add records to the database until I added a second table to my database (linked to main which uses an autonumber as the primary key). I realize that I need to get the primary key from table1 and (somehow) insert it into table2. That's where I get lost. :-( I've tried using the strSQL to grab the autonumber of the just added record from table1 and in the process I think I've seen just about every error message conceivable.

Relevant code:
Dim Conn

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath ("/mydatabase connection.mdb")


 Conn.Open

 Set RS = Server.CreateObject("ADODB.RecordSet")


  Conn.BeginTrans

 RS.LockType = adLockOptimistic
 RS.CursorType = adOpenDynamic
 RS.CursorType = adOpenKeyset

'Open Client Table.

RS.Open "SELECT * FROM Client", Conn


 RS.AddNew

 RS("Title") = Request.Form("title")
 RS("FirstName") = Request.Form("fname")
 RS("Initial") = Request.Form("initial")
 RS("LastName") = Request.Form("lname")
 RS("Address1") = Request.Form("address1")
 RS("Address2") = Request.Form("address2")
 RS("City") = Request.Form("city")
 RS("Prov") = Request.Form("prov")
 RS("PCode") = Request.Form("pcode")
 RS("CountryName") = Request.Form("country") 'This is populated from a separate CountryTable in the same database -- this one I did figure out
 RS("E-mail") = Request.Form("email")
 RS("Phone") = Request.Form("phone")
 RS("Format") = Request.Form("format")
 RS("EnrollDate") = Date()
 RS("ExpiryDate") = DateAdd("m", 6, Date)

 RS.Update
 RS.MoveLast

 RS.Close 'This worked to here as a single table

 'Open Business Table.


 RS.Open "SELECT * FROM Business", Conn

 RS.AddNew

 RS("BusName") = Request.Form("busname")
 RS("BusPhone") = Request.Form("busphone")
 RS("Ext") = Request.Form("ext")
 RS("Industry") = Request.Form("industry")
 RS("EmpNum") = Request.Form("empnum")
 RS("Email") = Request.Form("email")
 RS("Agency") = Request.Form("agency")
 RS("WebPage") = Request.Form("webpage")
 RS("Comments") = Request.Form("notes")

 RS.Update 'This is where I get the error: Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.

 RS.MoveLast

 RS.Close

   Conn.CommitTrans


I'm hoping someone can tell me (in plain English) just how I go about getting the autonumber from my justadded record and then how I use it to add records to my second table.

I'm about ready to give up and stick everything into a single table (not a great idea I know -- but it would work)

Thanks in advance for your patience. This 'grannie' appreciates all the help she can get (and they say they can't teach an old dog new tricks lol -- I'm betting you can point me in the right direction)

Kasperkatz




The Identity Value Is Not Being Returned!! PLZ HELP!
Hi All,

I have an SQL database with a table that has an integer field set as an identity (increment one).

I do with following:

Dim rsTable as ADODB.Recordset
dim iNewID as Integer

Set rsTable = new ADODB.Recordset
rsTable.open "TABLE NAME",cnData,Dynamic,Pessamistic

rsTable.Addnew
'Fill in fields
rsTable.Update

iNewID = rsTable("EQ_ID") 'This is the Int set as an identity

rsTable.close

The value in the iNewID should the be the automatic new number but it is blank.

Any ideas plz.

Thanx again for your help with my learning curve from ACCESS to SQL.

Jiggy!

Uniqueidentifier Or IDENTITY
Hi , as we know both uniqueidentifirt and identity is used for unique records .But I dont know the advantage of thoose ones.On which stuations must we use Uniqueidentifier .FOr example I will design a table for members , I have used identity until now but that question has stuck on me .Must I use Uniqueidentifier or continue with identity ...

tHanks ...

Select @@IDENTITY
Hi.
Why this code doesn't work. It stops here Code: Set adoRS = madoCMD.Execute
I've found an example for getting ID of inserting record here: http://www.kamath.com/tutorials/tut007_identity.asp
ERROR: "Character found after end of SQL statement"
Code:
Set adoCon = New ADODB.Connection
adoCon.Provider = "Microsoft.Jet.OLEDB.4.0"
adoCon.ConnectionString = "Data Source=" & App.Path & "objednavky.mdb"
adoCon.CursorLocation = adUseClient
adoCon.Open

strSQL = " INSERT INTO t_Order (OrderNumber,CustomerID) VALUES ('NewOrder'," & CStr(CustomerID) & " ) ; " _
      & " SELECT @@IDENTITY AS NewID"
  Set madoCMD.ActiveConnection = adoCon
  madoCMD.CommandType = adCmdText
  madoCMD.CommandText = strSQL
  Set adoRS = madoCMD.Execute
  mlOrderID = adoRS.NextRecordset.Fields("NewID").Value


Doesn't this provider support multiple SQL commands?
thanks for help.





Edited by - plsanek on 9/5/2006 8:36:23 AM

Use EVB To Get Device Identity
I have an eVB app that must run on a number of Pocket PCs 2003 which will all have the same user ID.
I need to bea able to programmatically identify each PDA when synchronising data with it.
If I go to Start-Settings-System Tab-Asset Viewer it lists (among other things) Identity details such as Asset Tag, etc.

Can anyone tell me how to programmatically access that information. I have tried the registry entry on the device 'HKEY_LOCAL_MACHINE, Ident' with the RegOpenKeyEx API but cannot get it to work.

Any help would be appreciated.

ADO Identity/Autonumber
After inserting a new record in a recordset using

rst.Addnew
rst.....
rst.....
rst.Update

I'd like to get the current identity(sql) or autonumber(access) or autoincrement(anywhere).

After the update, i put
variable = rst!identity_column
i assumed that the pointer of the recordset is still on the record that was added, but this does not work and I'm getting a null value in the variable.

How am i suppose to do this....?

ps.. I want to get the identity because I will insert it to another table...

Thanks

Winsock Socket Identity For PM
I have created a chat server. It has the basic features like LOGIN, LEAVE, JOIN, MESSAGE, etc, but not private messages. This is becuase I do not know how to identifiy a specifc socket for a user to forward the PM to. Can anyone explain how I would implement this, or even further, check out my source code and figure it out there? Thanks.

ADOX And Identity Fields...
Yuck,

I have figured out how to create an Autonumber (Identiy) field for an Access database. You have to set the

colNew.Properties("Autoincrement") = True

However, comma, there doesn't seem to be a similar property when one creates a new SQL Server column. Can anyone help?

Later


Roger Bogh
Yak & Quack Software Incorporated...

ADOX And Identity Fields...
Yuck,

I have figured out how to create an Autonumber (Identiy) field for an Access database. You have to set the

colNew.Properties("Autoincrement") = True

However, comma, there doesn't seem to be a similar property when one creates a new SQL Server column. Can anyone help?

Later


Roger Bogh
Yak & Quack Software Incorporated...

Getting Identity From Insert Statement
VB Code:
mysql = "INSERT INTO workouts (Muscle_Group, Workout_Name, Workout_Desc, Category) VALUES ('" & workoutData(1) & "', '" & workoutData(0) & "', '" & workoutData(10) & "', '" & workoutData(9) & "');select @@identity as 'WorkoutID';"gSet.Open mysqlWorkoutID = gSet!WorkoutIDgSet.Close


VB gives me an error about there being characters at the end of the query - is there another way to get the identity?

I can't use record count because its possible that some of the records may be deleted.

Thanks in advance,

Add/Remove Identity Column In SQL Svr Using VB And ADO.
I have a field UserID on a table.
What's the SQL command to change this to and from an identity column.
I have my reasons for doing this.
What I want to do is:

Make UserID an identity col
Do some data loading
Make UserID NOT an identity col

Woka

Can I Set Morethan One Identity Within The Same SQL Table
Hi

Is it possible to set more than one identity within the same tbl

Thanks

Caller Line Identity
Here is an interesting question. Is it possible to detect the caller line identity (number) of an incoming call in Visual Basic? If so how can this be accomplished.

Valiadte My Identity For Dialer
hello there,
This is the (validate my identity for dialer) security option for a dialer. this one i want to set to my dialer using vb.

Insert @@Identity Problem
Hi All,

I have a basic insert statement and I wish to get the @@Identity value returned... how

I think it is called the @@identity it's the value of the autonumber in the database of the record you just added?

Thanks

Return Identity Col Value Thru Code
I am using VB6 ADO to add a record to a MSSQL 2000 table that has an Identity field. Once the record is added I need to know the value of that Identity to add a record to another table. This is a multi-user db and I have found instances where the time stamp is the same on two records.
I have read the threads on @@IDENTITY but they all involve using a stored procedure to add the new record. I prefer not to do that.
Is there no way to get the IDENTITY value of a newly added record except through @@IDENTITY or am I missing something.

Returning @@IDENTITY Through Code
Hi:

I have a Stored Procedure that I'm trying to be fully functional by inserting a record and then returning the Seed of that record.

This is what I have:

CODE --> >Stored ProcedureCREATE PROC sp_InsertRecord
(@Test nvarchar (50))
AS
INSERT INTO Test (Test)
VALUES     (@Test)


SELECT @@IDENTITY

CommandBuilder And @@IDENTITY Columns
Hi,
I have a table with an identity column. The OleDbCommandBuilder builds an Insert statement, but does not repopulate my ID column with the new value.
I have tried updating the Insert command to have a Select after the Insert and adding a Parameter, but the DataAdapter.Update seems to reset the Insert statement.

Is there any way to get the @@IDENTITY column from the table into a DataSet short of reloading everything (as that will lose my current position)? Selecting @@IDENTITY from mytable in a separate statement returns nothing.

I have a stored procedure to return the new ID of an inserted row, but then DataSet isn't updated.

Any help appreciated.
Thanks!

 

Copyright © 2005-08 www.BigResource.com, All rights reserved