DataSource Controls :: Retrieve The Identity Value After Insert?

Jan 21, 2010

I have been searching on here for many hours and read many posts but for some reason I am being slow and cannot figure this out. I am writing a record and need to get the identity field back. I have tried many combinations based on what I have read but the below code is where I am sitting at now. it has appdatasource.ExecuteScalar() underlined and the error says 'ExecuteScalar' is not a member of 'System.Web.UI.WebControls.SQLDataSource'. I would be very grateful if someone could point out what I am missing to get this to work.

Protected Sub SubmitApp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitApp.Click

Dim appdatasource As New SqlDataSource
appdatasource.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString1").ToString
appdatasource.InsertCommandType = SqlDataSourceCommandType.Text
appdatasource.InsertCommand = "INSERT INTO APPLICATION (FirstName,MiddleName,LastName,AcceptTerms,IPv4Address,DateInserted) VALUES (@FirstName,@MiddleName,@LastName,@IPv4Address,@DateInserted);select @@SCOPE_IDENTITY"
appdatasource.InsertParameters.Add("FirstName", fname.Text)
appdatasource.InsertParameters.Add("MiddleName", minit.Text)
appdatasource.InsertParameters.Add("LastName", lname.Text)
appdatasource.InsertParameters.Add("DateInserted", DateTime.Now())
appdatasource.InsertParameters.Add("IPv4Address", Request.UserHostAddress.ToString)
Dim appid As Integer = appdatasource.ExecuteScalar()
End Sub

View 4 Replies


Similar Messages:

DataSource Controls :: Linq To Sql: How To Retrieve Identity Column Value Before For Inserting Any Record

Apr 3, 2010

I am in a serious trouble right now, i wanted to know that how to write a query in LINQ to SQL to retrieve identity column's current value before inserting any value.

I need this cos i m building a windows app n i need to display this value before inserting a record. I have tried DataContext.ExecuteCommand('DBCC CHECKIDENT (Tablename)') but it returns the number of rows modified.

View 2 Replies

DataSource Controls :: How To Get The Current Identity Number When Doing Insert

May 20, 2010

The scenario is that I wanna insert a record to the database via INSERT query and I need to user the identity number of this record in the INSERT query.

But I don't know how to achieve this.

Here is my table structure and code for your better understanding.

There are three columns in the Table: categoryID, categoryName, categoryPath. I need the path based on the categoryID which is an identity int column.

Now I used this code to do INSERT:

[Code]....

View 6 Replies

DataSource Controls :: Cannot Insert Explicit Value For Identity Column When Identity_Insert Is Set To Off

Jul 10, 2010

The wierd thing is this was working fine and then it just started throwing this error,

"Cannot insert explicit value for identity column in table 'Reports' when IDENTITY_INSERT is set to OFF."

Here is the code:

[Code]....

View 6 Replies

DataSource Controls :: Set A Insert Parameter That Receives The Record Identity In Codebehind

May 18, 2010

How do I set my insert identity return value parameter in codebehind? I have working code now but i have all of my parameters set in codebehindexcept the following:

[Code]....

View 6 Replies

DataSource Controls :: How To Retrieve ID After Insert Command When Using DataSet (xsd)

Nov 19, 2010

I have created a Dataset object (XSD file) whithin it there is a procedure called InsertWebsite.

In my code, I call this like this:

[Code]....

When I execute the commans it retrievs value "1" which is not the actual ID genereted by Insert event.....

How can I retrieve this ID and stll using the current design?

View 4 Replies

DataSource Controls :: Retrieve Scope_identity Value From Insert Statement In Codebehind

Jun 7, 2010

Iam inserting ,updating in one DBfunction .i want to retrieve identityvalue when in insert.for that am adding select SCOPE_IDENTITY() in insert statement.how i can i get this value??

public int funAddEdit_rtblIncidentTypesDB(clsCM_Inc_IncidentTypesData objData, int actiontype)
{
string qry = "";
if (actiontype == 1)
qry = "INSERT INTO _rtblIncidentType (cDescription,iEscGroupID,bAllowOverride,bRequireContract,iIncidentTypeGroupID,iWorkflowID,bAllowOverrideIncidentType,bPOIncidentType,cDefaultOutline) VALUES ('" + objData.cDescription + "'," + objData.iEscGroupID
+ ",'" + objData.bAllowOverride + "','" + objData.bRequireContract + "'," + objData.iIncidentTypeGroupID + "," + objData.iWorkflowID + ",'" + objData.bAllowOverrideIncidentType + "','" + objData.bPOIncidentType + "','" + objData.cDefaultOutline + "'); select
SCOPE_IDENTITY() ";
else if (actiontype == 2)
qry = "UPDATE _rtblIncidentType SET cDescription='" + objData.cDescription + "' WHERE idIncidentType=" + objData.idIncidentType;
int result = SqlHelper.ExecuteNonQuery(clsHelper.ConnectionString.ToString(), CommandType.Text, qry);
return result;
}

if i exceute the above query individually,it returns iddentity value,,bt unable to retireve the value in codebehind.

View 1 Replies

DataSource Controls :: Way To Retrieve Data From A Table, Modify And Insert It Into Another Table

Jun 13, 2010

Basically i deal with two tables.i have a table T1 of the following format:id company_name i need to read this data and create a table T2 as followsi wrote the following code. it worked fine for retrieving data and modification but fails to insert the modified data into the 2nd table.the error is, it does not recognise the value for @token

ArrayList dynarr=new ArrayList(); // global variable
protected void Button2_Click(object sender, EventArgs e)
{
int row = 1; int i;
string strcmd = null;
string Connection = "Data Source=....";
SqlConnection conn = new SqlConnection(Connection);
string str = "select company_name from T1 where ID=@ID";
[code]...

View 2 Replies

Forms Data Controls :: Get Identity Of Inserted Record Using Detailsview.insert()

Dec 6, 2010

This would seem to be quite a trivial task, however I am having trouble retrieving the identity of the record inserted using the detailsview.insert() in the code behind. It would seem that detailsview.DataKey.Value would contain this value, but it is null after the insert is performed.

View 4 Replies

Forms Data Controls :: Cannot Insert Explicit Value For Identity Column In Table 'UserDetails'

Mar 3, 2011

I have error:

Cannot insert explicit value for identity column in table 'UserDetails' when IDENTITY_INSERT is set to OFF.

I'm trying to insert a record through a BLL (Business Logic Layer) class with an 'Insert' button attached to the FooterTemplate of a GridView2. My code:

[Code]....

[Code]....

BLL layer code:

[Code]....

The field 'idUser' is autoincremented. When I use SqlDataSource with a DetailsView, add option it adds a record and autoincrements the 'isUser'.

View 7 Replies

Retrieve The PK Using @@identity?

Jan 10, 2010

I'm building a website using ASP.NET and SQL Server, and I use

SELECT PK FROM Table WHERE PK = @@identity

My question is which is better and more reliable to retrieve the last inserted PK for multiuser website, using @@identity or using this:

SELECT MAX(PK) FROM Table WHERE PK = Session ("UserID")

View 4 Replies

SQL Server :: How To Retrieve Identity Value

Oct 24, 2010

I need to retrieve the identity value after the record has been created for another datasource. I.E. When the record is created in SqlDataSource7 the identity value (4700) would be assigned to Label1.text and used in SqlDataSource8 to insert a new record.

How do I do this? In the CodeBehind retrieve the identity value using SqlDataSource7 Scope_Identity() and putting that value into the SqlDataSource8 ApplicantID column.

[code]...

View 4 Replies

Retrieve Web User's Identity Outside Of Request Scope?

Feb 14, 2011

I have an ASP.NET app that logs Audit reports using nHibernate's IPreUpdateListener. In order to set the current user in the Listener events, I was using System.Security.Principal.WindowsIdentity.GetCurrent(). This works fine when debugging on my machine, but when I move it to the staging server, I'm getting the ASP.NET process credentials, not the requesting user.

In the ASP.NET page, I can use Request.LogonUserIdentity (which works fine since I'm using integrated authentication), but how do I reference this user directly without having to pass it directly to my event? I don't want to have to pass this info through the pipeline because it really doesn't belong in the intermediate events/calls.

View 1 Replies

Retrieve Identity Value From Inserted Record's Primary Key?

Mar 14, 2011

i cannot retrieve the new identity value from an inserted record(via DataAdapter.Update) in my DataRow.

I'm using a strong typed Dataset as DAL. The table i want to update is joinded with other tables in the SelectCommand, hence the designer cannot automatically generate the insert-/update-/delete-commands and also it cannot "Refresh the DataTable" automatically. [URL]

I've tried to set AutoIncrement=true/false on the primary-key's DataColumn but the result is the same: last MAX-ID+1 instead of the actual ID the database generated(SQL-Server 2005 EP; pk datatype:int, Is identity:yes, Identity Increment:1).

This will be the wrong value f.e if another instance of the application inserted a record that the first instance yet not knows and therefore generates an ID that already exists.

To retrieve the new identity from db i've appended following to my insert-command's CommandText:

;SELECT CAST (SCOPE_IDENTITY() AS int) AS newIdRMA

Also i've tried to add an Output-Parameter to it's parameter-collection:

This is part of my code that updates the database and sets the new ID(that doesn't work):

[code]...

View 1 Replies

Security :: Unable To Retrieve Current.User.Identity.Name In II7

Feb 26, 2010

I'm in the middle of moving a web application from IIS6 to IIS7. I've enabled "Windows Authentication" and added <deny users="?" /> to the authorization section of my web.config file. When the app was running on IIS6 my users where able to access the web app without logging in because their windows login was automatically recognized. This does not seem to be the case in II7. I can not get a value for "Current.User.Identity.Name" in my ASP.Net code.

View 1 Replies

DataSource Controls :: Getting @@Identity Value From Stored Proc?

Jul 2, 2010

I've been self teaching SQL and asp.net and i'm a little stuck. I have a stored proc for the insert and then in my Insert inside my class it's not returning the ID after the insert as I am receiving an error message that NULL value has cannot be inserted. I want to add default values to a seperate table after the insert. I will provide my code below, if anyone can help me why the value is not going across?

[Code]....

View 7 Replies

DataSource Controls :: Reset Identity Column To A New Value?

Jan 16, 2010

Resetting IDENTITY column to a new valueDuring application development we always entry some test data also our tester test with test data and as a result if the table contains IDENTITY columns( specially ID column) which incremented to the number of data already entered.

However, when the application goes running with real data to the client and the client want his ID values from starting 1, then we need to RESEED the value of the IDENTITY column of the table after clearing all data. This can be done as bellows:

DBCC CHECKIDENT (TableName, RESEED, 0)

However, can be reseed with any values instead of zero(0) in the above statement.

View 2 Replies

DataSource Controls :: How To Reset Identity Column Value

Jun 14, 2010

I have an identity column that increment by 1 on every insert. I have deleted all the rows using delete query but the identity coulumn is still not reseting to zero, how do i reset it, as it was when the table was first created.

View 4 Replies

DataSource Controls :: Add Identity To Existing Column

Jun 3, 2010

I have created small database prods. I have created one table Products. I have given columns like productid, productname, price. after creating table. I got an idea to add identity to productid ie., auto increment. how to add identity to existing column.

View 5 Replies

DataSource Controls :: Use Of Scope_identity(), @@identity And Ident_current?

Jan 19, 2010

I'm trying to insert data into two tables that are related within a store procedure. After the first insert I want to get the id of the inserted row to use as a parameter during the insertion of data in the other table. I'm sure this is a common task, and I have looked into things like scope_identity(), @@identity and ident_current. However I'm not sure exactly how to use the id as a parameter.My attempt now looks like:

DECLARE @RETURN_VALUE
INSERT INTO Table1(test_name) VALUES ('asdf')
@RETURN_VALUE = SCOPE_IDENTITY()
INSERT INTO Table2(test_name) VALUES(@RETURN_VALUE)

View 4 Replies

DataSource Controls :: How To Use User.identity In A Where Statement In Sqldatasource

Jul 6, 2010

I was wondering how I could use user.identity in a where statement in sqldatasource to return results for a user profile. I already have a table that stores the username. Just need to return it's results.

View 5 Replies

DataSource Controls :: Identity Column Missing Sometime Values?

May 31, 2010

I have one table it's contain multiple columns and one of them is

[Call_Ref_No] [numeric](18, 0) IDENTITY(1,1) NOT NULL

In this column I am facing issue is some time its missing the identity value... For example

1
2
3
5
6
8
9

Here in this example 4 and 7 is missing...I could not able to find these two reference in my table so what I can do? How I can stop this occurrence.

View 13 Replies

DataSource Controls :: Get The Identity Column On Which The Record Is Inserted

Jun 9, 2010

I am trying to get the identity column on which the record is inserted but i couldn't using stored procedure
see

[Code]....

My Code Using ASP.NET C# i am trying to display the identity in textbox

[Code]....

View 6 Replies

DataSource Controls :: Retrieving Identity Value After Using DataAdapter.Update?

Jul 29, 2010

I am not sure how to do this. I would like to merge the identity back into the dataset.

View 2 Replies

DataSource Controls :: Identity Data Type - Not Available In SQL Server?

Jan 31, 2011

http://forums.asp.net/p/1625331/4177299.aspx#4177299?Is+Identity%3f+in+table+definition+not+available

I tried all that was suggested in the above link..but I just cannot see the Identity data type option in the drop down. How can I set one field as a Identity data type if I dont see it?

View 3 Replies







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