Where Is The Identity Property Stored?

Oct 20, 2006

I assume that the identity property is stored within a given database, so there should be no need to run dbcc checkident after restoring from a backup. Is this a correct assumption?

View 1 Replies


ADVERTISEMENT

Identity Property

Jul 6, 2007

Hello friends,
I am using sql server 2005. In some tables to create the column Autoincrement I had set the 'Idetity Specification' property to 'Yes'. I want to know that how can we do it through sql scripts i.e. by writing query.
Please let me know
Thanks & RegardsGirish Nehte

View 6 Replies View Related

Dropping The Identity Property

Dec 19, 2001

Hi,

I have a VB script that I am using to run various DTS procedures. One of these involves using DataPumpTransformCopy to copy data from one table to another. The destination table has an Identity field that I would like to disable for the duration of the Transform.

I have tried opening a Command Object and running the "SET IDENTITY_INSERT" function beofre and after the Transform but although it doesn't produce any errors it doesn't seem to actually do anything...

I figure I need to try using the ALTER TABLE to disable the IDENTITY but I can't find an example of how to do this anywhere.. can anyone help me out here?

Many Thanks,

Seoras

View 1 Replies View Related

Removing Identity Property

Jul 23, 2004

How can i remove identity property of a particular table with sql command.
Thanks.

View 1 Replies View Related

Identity Column Property SQL SERVER

Apr 2, 2007

hi
i export tables from Local to Online Server But some tables have a column with Identity=True
But after export tables that Property is not True How I can change it True With Query Analyzer????????/

View 1 Replies View Related

Drop Identity Property Of A Column

May 24, 2005

Is there a way to remove the Identity property of a column in SQL Server 2000? 
The statement:
<code>
ALTER TABLE <table name> ALTER COLUMN <column name> DROP IDENTITY
</code>
returns a syntax error.
Thank you,
Jeff

View 11 Replies View Related

Replicating Tables With IDENTITY Property

Oct 24, 2000

Hi,
Please let me know if it is possible to replicate a table with identity property defined in it. Both the publisher and subscriber tables have identity property defined. Which option should be used while setting up transactional replication to allow the identity values at the publisher pushed to the subscriber, which also has identity property defined? Not for replication option with the identity property also fails. Whichever option I choose I get the error, 'An explicit value for the identity column in table 'jobs_id_nfr' can only be specified when a column list is used and IDENTITY_INSERT is ON.' This works only if the identity property is not defined at the subscriber. But, I need to have the identity property defined at the subscriber also because the subscriber should be an exact copy of production.

Thanks in advance,
Praveena

View 1 Replies View Related

How To Add Identity Property To Existing Table?

Mar 2, 2004

Has anybody ever tried to do this. I can't figure it out. All I want to do is take an existing table that already has values in the column that I want to change and add the identity property to yes and set the identity seed and increment to a specific number. I know you can do it in the CREATE TABLE statement but is there a way to use the ALTER TABLE command?

View 4 Replies View Related

IDENTITY Property & Timeout Issue.

Apr 9, 2008

Hi all,

Have anyone faced the timeout issue when setting a IDENTITY property of a column to NO.

Is there any way to resolve it ?

Note : The table on which I'm doing the operation is having approx 50 million records.

Thanks,

Hariarul.


I get the below error :

'TrnBillDetail' table
- Unable to modify table.
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

View 2 Replies View Related

Removing Identity Property Of Column

Sep 28, 2007

How to remove an Identity property for an Identity Column

View 1 Replies View Related

Is There Any Way To Remove IDENTITY Property On Table?

Aug 1, 2007



Is there any way to remove IDENTITY property on particular table? I tried removing IDENTITY property using Manangement studio, but this operation behind the scene use migration concept that is by creating tmp table and then populating with data; droping the orginal and renaming the tmp back to original.

Second, i want some kind of generic solution using certain system table like aya.sysobjects, sys.identitycolumn etc such a way that i should be able to remove the idenity property from all of the table accross a database.

Mandip

View 5 Replies View Related

Find All Columns That Have Identity Property

Mar 19, 2008



How do i Find all Columns that have Identity Property in a database. That is i will like to know all columns in a database that are identity columns.

I am using SQL Server 2005. Thanks

View 4 Replies View Related

Attach IDENTITY Property To An Existing Column

Mar 30, 2006

Hi All,
Can any body tell me that how we can attach IDENTITY property to an existing int column

View 1 Replies View Related

Alter Identity Property Of A Column To NOT FOR REPLICATION

Jul 20, 2005

i need to alter all foreign keys in my database and uncheck the"Enforce relationship for replication" check box. Using the EM, Iextracted the code snippet below. unfortunately, when i run this testfrom query analyzer, then go back into the EM, the box is stillchecked.can anyone tell me what i am missing? any advice on unsetting thisattribute globally would be appreciated!BEGIN TRANSACTIONSET QUOTED_IDENTIFIER ONSET TRANSACTION ISOLATION LEVEL SERIALIZABLESET ARITHABORT ONSET NUMERIC_ROUNDABORT OFFSET CONCAT_NULL_YIELDS_NULL ONSET ANSI_NULLS ONSET ANSI_PADDING ONSET ANSI_WARNINGS ONCOMMITBEGIN TRANSACTIONALTER TABLE dbo.CustomerCustomerDemoDROP CONSTRAINT FK_CustomerCustomerDemo_CustomersGOCOMMITBEGIN TRANSACTIONALTER TABLE dbo.CustomerCustomerDemo WITH NOCHECK ADD CONSTRAINTFK_CustomerCustomerDemo_Customers FOREIGN KEY(CustomerID) REFERENCES dbo.Customers(CustomerID) NOT FOR REPLICATIONGOCOMMITthanks!!

View 4 Replies View Related

What Are Cons And Pros For Using IDENTITY Property As PK In SQL SERVER 2000?

Jul 20, 2005

Hi All!We are doing new development for SQL Server 2000 and also moving fromSQL 7.0 to SQL Server 2000.What are cons and pros for using IDENTITY property as PK in SQL SERVER2000?Please, share your experience in using IDENTITY as PK .Does SCOPE_IDENTITY makes life easier in SQL 2000?Is there issues with DENTITY property when moving DB from one serverto another? (the same version of SQL Server)Thank you in advance,Andy

View 49 Replies View Related

Dropping Or Removing The Identity Property From An Existing Column

Mar 7, 2008

How do i drop/remove the identity property for an existing column in all Tables where the Identity column is a primary key.
The Script below was used to find all the tables that have an Identity Column as a primary key in a database. Now i want to remove the identity property from the Identity Columns that have a primary key in the database.


select pk.table_name, c.column_name,

from information_schema.table_constraints pk

INNER JOIN information_schema.key_column_usage c ON c.TABLE_NAME = pk.TABLE_NAME

and c.constraint_name = pk.constraint_name

where constraint_type = 'PRIMARY KEY'

and COLUMNPROPERTY(object_id(pk.table_name), column_name, 'IsIdentity') = 1

ORDER BY pk.table_name, c.column_name

View 8 Replies View Related

Property 'TextHeader' Is Not Available For Stored Procedure

Oct 10, 2007

Hi,

I'm getting an error when i try to open an SP. The error message is: Property 'TextHeader' is not available for Stored Procedure.

This procedure also has a small lock icon with it.

Can anybody tell me what's the problem with this SP?

---
Thanks in advance,
Manjunath HK

View 3 Replies View Related

Permissions To View Stored Procedure Property

Feb 9, 2007

My Production servers are SQL Server 2005 x64. I would like to allow my developers the ability to look at permissions on production stored procedures but not be able to change those permissions or alter the production code. What has to be set to allow this sort of security.

View 8 Replies View Related

Changing Code Page Property Using Property Expression Doesn't Work

Jun 16, 2006

I am having problems exporting data into a flat file using specific code page. My application has a variable "User::CodePage" that stores code page value (936, 950, 1252, etc) based on the data source. This variable is assigned to the CodePage property of desitnation file connection using Property expression.

But, when I execute the package, the CodePage property of the Destination file connection defaults to the initial value that was set for "User:CodePage" variable in design mode. I checked the value within the variable during runtime and it changes correctly for each data source. But, the property of the destinatin file connection doesn't change and results in an error.

[Flat File Destination [473]] Error: Data conversion failed. The data conversion for column "Column01" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".

[DTS.Pipeline] Error: The ProcessInput method on component "Flat File Destination" (473) failed with error code 0xC02020A0. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.

If I manually update the variable with correct code page and re-run the ETL, everything works fine. Just that it doesn't work during run-time mode.

Can someone please help me resolve this.

Thanks much.

View 5 Replies View Related

Value Of A Readonly Property Of Custom Task Is Not Updated In Property Window

Apr 17, 2008

Hi,

I developed a simple custom control flow component which has several read/write properties and one readonly property (lets call it ROP) whichs Get method simple returns the value of a private variable (VAR as string). In the Execute method the VAR has a value assigened. When I put the value of ROP or VAR into MsgBox I can see the correct value. However when I execute the component I can not see the value of the ROP in the property window. I see the property but its value is empty string. For example when I put a breakpoint to postexecute or check the property before click OK in a MsgBox I would expect that the property value would be updated in SSIS as well. Is there a way how to display correct values of custom tasks properties in property window?

Thanks for any hints.

View 3 Replies View Related

(URGENT) Cannot Be Written To The Property. The Expression Was Evaluated, But Cannot Be Set On The Property

May 7, 2008

Untill recently I had a smooth running SSIS package,but suddenly it throws error syaing
"OnError,,,,,,,The result of the expression

"@[User:trTextFileImpDirectory] +"SomeTextStringHere"+ @[User:trANTTextFileName] +(DT_STR,30,1252) @[User:taging_Date_Key]+ "SomeTextStringHere"
" on property "ConnectionString" cannot be written to the property. The expression was evaluated, but cannot be set on the property."

I have child SSIS package running under a parent package (through execute package task)

I have few flat file connection managers in child package for text file import , in which I am building text file path dynamically at run time by assigning an expression in connection string property of connection manager.
The Expression is as follows



"@[User:trTextFileImpDirectory] +"SomeTextStringHere."+ @[User:trANTTextFileName] +(DT_STR,30,1252) @[User:taging_Date_Key]+ +"SomeTextStringHere"

Where @[User:trTextFileImpDirectory] is a variable which contains path of directory containg text
files.Value in this variable is assigned at runtime from parent package's variable,which in turns fetch
value from a configuration file on local server.

With my current configuration this path has been configured to some other server's directory over network ( I.e my package picks text files from some other servers folder over network)

While
"Some string here"+ @[User:trANTTextFileName]" part of file name string.

(DT_STR,30,1252) @[User:taging_Date_Key] Contain the date of processing ,value in this variable is also picked up at run time from parent package variable.

1) So can someone give me some insight into possible reason of failures.
2) Is it possible that problem arises if directory (from which I m picking text files) is assigned password or is there exist some problem in accessing forlders over network ?
3) Or there can be some problem in package configuration at design time( I.e where I m assigning value in variable from parent package vriables)?




View 10 Replies View Related

Where Is The Identity Stored?

Jan 24, 2000

Where is the identity stored for a column? Need to know where the value is stored that SQL looks at to increment an Identity Column.

Thanks for your time.

View 1 Replies View Related

@@Identity In Stored Procedure

Jun 28, 2007

Hi,I have a stored procedure  that insert data into 2 temp tables. The problem that I have is when I insert a data into a first table, how do I get the @@identity value from that table and insert it into the second table?? The following code is what I have:Create #Temp1    @StateID Identity,    @State nvarchar(2),    @wage moneyINSERT INTO #Temp1 (State, wage)SELECT State, Wage FROM Table1 INNER JOIN Table2 ON Table1.Table1_ID = Table2.Table2_IDCreate #Temp2    @ID Identity    @EmployeeID int        @StateID Int    @Field1 Money    @Field2 MoneyINSERT INTO #Temp2 (EmployeeID, StateID, Field1, Field2)SELECT EmployeeID, StateID, Field1, Field2 FROM SomeTable 

So, The first part I created a #Temp1 table and insert data into the table. Then after the insert, I want the @@Identity value and insert into the #Temp2 table. This is my first time doing stored procedure, so, I am wondering how do I retrieve the @@identity value and put into the second select statement. Please help. ahTan 

View 9 Replies View Related

@@IDENTITY (without Stored Procedures)

Mar 6, 2008

Hi guys, I found this page which explains how to get hold of an @@IDENTITY/the last identity column added from your database without using a stored procedure (I haven't been using these).
http://blog.developers.ie/cgreen/archive/2007/08/20/sqldatasource-getting-identity-after-insert.aspx
 Using that as a basis, I have been using the following but nothing is showing in the label that should return the latest identity. Any ideas what I'm doing wrong? I can't figure out why it's not returning anything (the data is going into Orders table fine).
InsertCommand="INSERT INTO [Orders] (...) VALUES (...); SELECT @OrderID = @@Identity"
(Where the OrderID is the PK IDENTITY (auto inc) column of "Orders" table)
my insert command:
<InsertCommands>
            <asp:Parameter Direction="Output" Name="OrderID" Size="4" Type="Int16" />
</InsertCommands>
 
Then I click a button to update the orders table, and ideally I'd see the updated OrderID column appear in the label4 below, but I don't :(
 
C# Code:
    protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)    {       object newId = e.Command.Parameters["@OrderID"].Value;       Label4.Text = newId.ToString();
    }

View 2 Replies View Related

Grab IDENTITY From Called Stored Procedure For Use In Second Stored Procedure In ASP.NET Page

Dec 28, 2005

I have a sub that passes values from my form to my stored procedure.  The stored procedure passes back an @@IDENTITY but I'm not sure how to grab that in my asp page and then pass that to my next called procedure from my aspx page.  Here's where I'm stuck:    Public Sub InsertOrder()        Conn.Open()        cmd = New SqlCommand("Add_NewOrder", Conn)        cmd.CommandType = CommandType.StoredProcedure        ' pass customer info to stored proc        cmd.Parameters.Add("@FirstName", txtFName.Text)        cmd.Parameters.Add("@LastName", txtLName.Text)        cmd.Parameters.Add("@AddressLine1", txtStreet.Text)        cmd.Parameters.Add("@CityID", dropdown_city.SelectedValue)        cmd.Parameters.Add("@Zip", intZip.Text)        cmd.Parameters.Add("@EmailPrefix", txtEmailPre.Text)        cmd.Parameters.Add("@EmailSuffix", txtEmailSuf.Text)        cmd.Parameters.Add("@PhoneAreaCode", txtPhoneArea.Text)        cmd.Parameters.Add("@PhonePrefix", txtPhonePre.Text)        cmd.Parameters.Add("@PhoneSuffix", txtPhoneSuf.Text)        ' pass order info to stored proc        cmd.Parameters.Add("@NumberOfPeopleID", dropdown_people.SelectedValue)        cmd.Parameters.Add("@BeanOptionID", dropdown_beans.SelectedValue)        cmd.Parameters.Add("@TortillaOptionID", dropdown_tortilla.SelectedValue)        'Session.Add("FirstName", txtFName.Text)        cmd.ExecuteNonQuery()        cmd = New SqlCommand("Add_EntreeItems", Conn)        cmd.CommandType = CommandType.StoredProcedure        cmd.Parameters.Add("@CateringOrderID", get identity from previous stored proc)   <-------------------------        Dim li As ListItem        Dim p As SqlParameter = cmd.Parameters.Add("@EntreeID", Data.SqlDbType.VarChar)        For Each li In chbxl_entrees.Items            If li.Selected Then                p.Value = li.Value                cmd.ExecuteNonQuery()            End If        Next        Conn.Close()I want to somehow grab the @CateringOrderID that was created as an end product of my first called stored procedure (Add_NewOrder)  and pass that to my second stored procedure (Add_EntreeItems)

View 9 Replies View Related

Problem With @@IDENTITY In Stored Procedure

Feb 2, 2007

Hello !
I just can't access @@IDENTITY in my requests !Here is my stored procedure : (I removed a few lines for clarity)set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AssignerLicence]
(
@Apprenant int = 0
)
AS
BEGIN
SET NOCOUNT ON;

DECLARE @NBLICENCES int
DECLARE @COMMANDEID int
DECLARE @LICENCEID int

SET @NBLICENCES = (SELECT SUM(commande_licences_reste)
FROM Commande
WHERE commande_valide = 1)

IF
@NBLICENCES > 0
BEGIN

UPDATE Commande
SET commande_licences_reste = (commande_licences_reste - 1)
WHERE commande_id =
(SELECT TOP 1 C_min.commande_id
FROM Commande AS C_min
WHERE C_min.commande_licences_reste > 5
ORDER BY C_min.commande_licences_reste ASC,
C_min.commande_date ASC);

SET @COMMANDEID = @@IDENTITY

INSERT INTO Licence (licence_date_debut, commande_id)
VALUES (GETDATE(), @COMMANDEID)

SET @LICENCEID = @@IDENTITY

UPDATE Apprenant
SET licence_id = @LICENCEID
WHERE apprenant_id = @Apprenant

END

END
But it always throws an error saying that I can't insert null into commande_id (basically, I think @@IDENTITY isn't executed at all)
Any idea why it doen't works ?
Thanks !

View 1 Replies View Related

Set Identity Not Working For Stored Procedure

Jan 31, 2008

Hi can someone tell me whats wrong with this stored procedure. All im trying to do is get the publicationID from the publication table in order to use it for an insert statement into another table. The second table PublicaitonFile has the publicaitonID as a foriegn key.
Stored procedure error: cannot insert null into column publicationID, table PublicationFile - its obviously not getting the ID.
ALTER PROCEDURE dbo.StoredProcedureUpdateDocLocField
@publicationID Int=null,@title nvarchar(MAX)=null,@filePath nvarchar(MAX)=null
ASBEGINSET NOCOUNT ON
IF EXISTS (SELECT * FROM Publication WHERE title = @title)SELECT @publicationID = (SELECT publicationID FROM Publication WHERE title = @title)SET @publicationID = @@IDENTITYEND
IF NOT EXISTS(SELECT * FROM PublicationFiles WHERE publicationID = @publicationID)BEGININSERT INTO PublicationFile (publicationID, filePath)VALUES (@publicationID, @filePath)END
 

View 5 Replies View Related

Stored Procedure And Assigning @@IDENTITY Value

Nov 3, 2003

In the following stored procedure I would like to test whether @TopCategoryID is null. If so I would like to insert the @CategoryID value into the @TopCategoryID value. So, once @CategoryID recieves the @@IDENTITY value, how do I enter this same value into @TopCategoryID as well???



CREATE PROCEDURE sp_CT_InsertCategory



@Namevarchar(50),
@Description varchar(250),
@topCategory bit,
@ParentCategoryID int,
@TopCategoryID int,
@CategoryID int OUTPUT
AS
DECLARE @CurrID int


IF @CurrID IS NULL
BEGIN

INSERT
INTO CT_Category
(CategoryName, CategoryDescription, topcategory, parentcategoryid, topcategoryid)
VALUES
(@Name, @Description, @topcategory, @ParentCategoryID, @TopCategoryID)

SET @CategoryID = @@IDENTITY

IF @@ERROR > 0
BEGIN

RAISERROR ('Insert of Category failed', 16, 1)
RETURN 99

END

END
ELSE
BEGIN

SET @CategoryID = -1

END
GO



Thanks in advance

View 9 Replies View Related

Returning @@IDENTITY FROM Stored Proc

Nov 15, 2005

I am trying to get the identity of an inserted record using this SP:

<code>
ALTER PROCEDURE acereal_Admin.AuctionInsertCommand
(
    @AuctionID Int OUTPUT,
    @StartDate char(255),
    @StartTime char(255),
    @Location char(255),
    @Title char(255),
    @Description char(255),
    @Images char(255)
)
AS
INSERT INTO Auctions
(
    StartDate,
    StartTime,
    Location,
    Title,
    Description,
    Images
)
VALUES
(
    @StartDate,
    @StartTime,
    @Location,
    @Title,
    @Description,
    @Images
)

SELECT     AuctionID AS ID
FROM         Auctions
WHERE     (AuctionID = @@IDENTITY)
</code>

Then, I am using this class for a file called dataaccess.cs to return the ID:

<code>
public string SaveImageName(string ImageName, string AuctionID)
        {
            SqlConnection
sqlConnection = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

           
this.newSqlCommand = new
System.Data.SqlClient.SqlCommand("[AuctionImageSave]", sqlConnection);
           
this.newSqlCommand.CommandType =
System.Data.CommandType.StoredProcedure;

            SqlParameter
paramImagePath = new System.Data.SqlClient.SqlParameter("@ImagePath",
System.Data.SqlDbType.Char, 255);
            paramImagePath.Value = ImageName;
            this.newSqlCommand.Parameters.Add(paramImagePath);

            SqlParameter
paramAuctionID = new System.Data.SqlClient.SqlParameter("@AuctionID",
System.Data.SqlDbType.Int, 4);
            paramAuctionID.Value = AuctionID;
            this.newSqlCommand.Parameters.Add(paramAuctionID);

            SqlParameter
paramImageID = new System.Data.SqlClient.SqlParameter("@ImageID",
System.Data.SqlDbType.Int, 4);
            paramImageID.Direction = ParameterDirection.Output;
            this.newSqlCommand.Parameters.Add(paramImageID);

            //Return SqlDataReader Struct
            this.newSqlCommand.Connection.Open();
            this.newSqlCommand.ExecuteNonQuery();
            this.newSqlCommand.Connection.Close();

            int returnID = (int)paramImageID.Value;

            return returnID.ToString();
        }
</code>

The above code returns null.

Can anyone tell me what I am doing wrong?

THanks, Justin.

View 2 Replies View Related

Return Identity In Stored Procedure

Mar 23, 1999

I have a stored procedure where I am passing in several strings which are concatenated to form an Insert SQL statement. I then return the identity value from the insert - problem is, the identity value is coming back NULL.

Here is the sp. Any ideas?

CREATE PROCEDURE sp_ExecuteInsert
@pIdentity int OUTPUT,
@pSQL1 varchar(255),
@pSQL2 varchar(255) = NULL,
@pSQL3 varchar(255) = NULL,
@pSQL4 varchar(255) = NULL,
@pSQL5 varchar(255) = NULL,
@pSQL6 varchar(255) = NULL,
@pSQL7 varchar(255) = NULL,
@pSQL8 varchar(255) = NULL
AS

EXECUTE (@pSQL1 + @pSQL2 + @pSQL3 + @pSQL4 + @pSQL5 + @pSQL6 + @pSQL7 + @pSQL8)

SELECT @pIdentity = @@IDENTITY
GO

FYI, the real problem I am trying to solve is simply to return the identity after an insert. I could write a simple insert sp that returns the identity, but my code is written to handle generic situations and build an INSERT statement as needed. So if there are any other ideas of executing an insert statement and getting the identity, please let me know.

Thanks...

View 4 Replies View Related

Stored Procedure Conditionally Using @@Identity

Feb 21, 2006

Im having a play using @@identity

I want to insert some data into a table

Get the AutoID value on the inserted data

then insert some other data into another table
and set its id value to the captured @@identity

My question
I only want to do the second insert only if
@FieldValue2 contains a value ie not empty

below is a basic procedure without conditonal part



Code:

CREATE PROCEDURE conditional_Insert

@FieldID As int,
@FieldValue As Nvarchar(50),
@FieldValue2 As Nvarchar(50)
AS

declare @id int

set nocount on

INSERT INTO Table1(fieldID,fieldvalue)
VALUES( @FieldID, @FieldValue)

set @id = @@identity

INSERT INTO Table2(fieldID2, FieldValue2)
VALUES(@id, @FieldValue2)

select @id
GO

View 2 Replies View Related

IDENTITY Values In A Stored Procedure

Oct 18, 2005

Hi All,
This is my stored procedure

CREATE PROCEDURE testProc AS
BEGIN
CREATE TABLE #tblTest(ID INT NOT NULL IDENTITY, Col1 INT)
INSERT INTO #tblTest(Col1)
SELECT colA FROM tableA ORDER BY colA

END


This is my simple procedure, I wanted to know whether the IDENTITY values created in #tblTest will always be consistent, I mean without losing any number in between. i.e. ID column will have values 1,2,3,4,5.....
or is there any chance of ID column having values like 1,2, 4, 6,7,8....

Please reply...
qa

View 2 Replies View Related

SCOPE IDENTITY Using SqlDataSource WITHOUT Stored Proc

Oct 27, 2006

Ok, So I am trying to do 1 insert into a table and then insert more information into another table but I need to get the [TKTNUM] (the column with the idenity increment on it) value that was auto-generated when the insert was done. I have done a search and I am well aware that this are tons of posts on this subject already that is how I found out to use the SCOPE IDENTITY(). But nobody is using the insert syntax that I am using and since I am new, I don't understand any of it. I think they are using ADO.NET. I am extremely new to ASP.NET so take it easy on me ok guys... But can someone take a look at my code and tell me what the problem is. Again, I'm new so I am learning as I go so I might be missing something really stupid. Any help would be greatly appreciated. O yeah, I am running this code in a button click event NOT in a stored procedure (dont really know now to use those anyway).Here is my code:Protected Sub submitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)Dim newTktNumIf Page.IsValid ThenDim it3Conn As SqlDataSource = New SqlDataSource()it3Conn.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString1").ToStringit3Conn.InsertCommand = "INSERT INTO [IT_TICKET] ([REQUEST_DATE], [LOGGED_BY], [REQUESTED_BY], [TKTSTATUS],[NEEDED_DATE]) VALUES (@REQUEST_DATE, @LOGGED_BY, @REQUESTED_BY, @TKTSTATUS,@NEEDED_DATE); SELECT @newTktNum = SCOPE_IDENTITY()"it3Conn.InsertParameters.Add("REQUEST_DATE", DateTime.Now.ToString)it3Conn.InsertParameters.Add("LOGGED_BY", User.Identity.Name)it3Conn.InsertParameters.Add("REQUESTED_BY", User.Identity.Name)it3Conn.InsertParameters.Add("TKTSTATUS", "NEW")it3Conn.InsertParameters.Add("NEEDED_DATE", needByTB.Text.ToString)it3Conn.Insert()End IfMsgBox("Ticket Number: " & newTktNum & " has been created", MsgBoxStyle.OkOnly, "Ticket Created")End Sub 

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved