VS 2012 Formview Control - Insert And Return Identity

Jun 5, 2013

I want to know if it's possible to return the identity value after an insert working with just the insertCommand and the insert parameters - something like this (but this isn't working):

<asp:SqlDataSource ID="sqlCustomerInformation" runat="server" ConnectionString="<%$ ConnectionStrings:SloanLEDLightingSystemsQuoteToolConnectionString %>"
SelectCommand="SELECT quoteCustomerInformationId,contactname FROM QuoteCustomerInformation order by quoteCustomerInformationId"

[Code] ....

Not sure what's wrong with my code. Should I be doing this in the code behind? I'm also confused as to how I would then retrieve the identity value in the code behind - on iteminserted.

View 2 Replies

Similar Messages:

VS 2012 / Get FormView Control Values To Remain After Insert And Update?

Jun 4, 2013

I have a web app I'm creating and a form that has a formview control on it. The form's default is set to insert and when the user enters data and clicks save, the data gets saved to the database; only problem is that the form then clears all the data out of the controls.

Upon saving after updating or inserting, I'd like to set the form mode to edit and also have it retain the values they input into the form. I've tried a few things and have not had any luck.



Protected Sub frmCustomerInformation_ItemInserted(sender As Object, e As FormViewInsertedEventArgs)
' Make sure record inserted properly.
If e.Exception Is Nothing Then
If e.AffectedRows > 0 Then
litMessage.Text = "Customer Information saved."

[Code] ....

What mode does the formview control have by default after it executes the ItemInserted method? Also, what is the prper way to do this?

View 2 Replies

Web Forms :: Nested Formview - Link Parent Formview Control In Editmode With Child Formview Control In Insertmode

Apr 8, 2010

i have the following scenario: one formview. when in editmode there is a child formview linked to the other by a column value. i need to take the value of one of the values of parent formview controls and set it to a textbox of child formview in insert mode. I wish to know which event should I use in codebehind to bind both controls? (that escenario will have paging and must keep the binding as if it was master detail)

View 9 Replies

C# - Set The One Template For Edit/insert And View In My Custom FormView Control

Aug 17, 2010

I would like to set the one template for edit/insert and view in my custom FormView control . But i got these odd exception Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.Table'.

public class CustomFormView : FormView
[PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(FormView), BindingDirection.TwoWay)]
public IBindableTemplate FormTemplate { get; set; }
protected override void OnInit(EventArgs e)
if (FormTemplate != null)
if (CurrentMode == FormViewMode.Edit)
edited :
in the first step , I created the new user control and added a formview ("FV")
public partial class Form : UserControl
private IBindableTemplate _template = null;
TemplateContainer(typeof(FormView), System.ComponentModel.BindingDirection.TwoWay)]
public IBindableTemplate FormTemplate { set;get }
protected void Page_Init()
if (FormTemplate != null)
FV.InsertItemTemplate = FV.EditItemTemplate = FormTemplate;
if (!IsPostBack) FormTemplate.InstantiateIn(FV);

Now , I want to convert this user control to web control.

View 1 Replies

Web Forms :: Select Insert Edit Update Delete Using FormView Control

Sep 20, 2015

my EditItemTemplate is not appear in my page, when i load my page it's does'nt exist but I already change my DefaultMode to Edit

View 1 Replies

Forms Data Controls :: How To Put The File Upload Control Into The "insert Item" Template Of Formview Control

Nov 12, 2010

I'm using visual web developer and MS.Access and have the following created. 1. A formview control to enter data into the database 2. A File upload control that allows users to upload files. But however i'm unable to include the file upload control in the formview control. How can i achieve this? Below is the code for the page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewRecord.aspx.cs" Inherits="NewRecord" %>

View 2 Replies

Web Forms :: FormView Control Insert Mode - Assign A System-calculated Value To A Text Box?

Feb 1, 2010

When a FormView control is in insert mode, a data entry form is shown where the user will type a value into each textbox corresponding to a table column.

How do I disable data entry for one of these textboxes and instead, assign a system-calculated value to that text box?

View 4 Replies

Return Identity Column Value From Table After Inserting Row?

Sep 29, 2010

I am inserting data into Employee table using stored procedure.In employee table EmpNo is identity column.Once i insert data into table stored procedure should EmpNo i.e identitycolumn value.

correct my stored procedure to returm EMpNo Identity column after inserting row.

alter procedure SAR_Sp_AddEmployee(@EmpName varchar(10),@CampaignID int,@startDate datetime) as insert into EmpMaster values(@EmpName,@CampaignID,@startDate)

View 5 Replies

Forms Data Controls :: FormView Must Be In The Insert Mode To Insert A Record?

Jan 21, 2011

I use GridView & FormView to update a record. but when I click the "save" button, throw an except : FormView must be in the insert mode to insert a record. The record has been updated success, and I didn't change the mode of the FormView, how this error comes?

View 3 Replies

Forms Data Controls :: Filter On User.Identity.Name - FormView Disappearing From The Web Page?

Oct 21, 2010

I have a FormView and the SELECT statement I have is as follows:

SelectCommand="SELECT [UserName], [Full_Name_1], [Full_Name_2], [Email], [Address], [City], [State], [Zip_Code], [Home_Phone], [Cell_Phone] FROM [Homeowners] WHERE ([UserName]='<%$ User.Identity.Name %>')"... but it results in the FormView disappearing from the web page. Note: at the top of the page,
<%= user.identity.name %> displays the name fine, so user.identity.name does contain the info I'm looking for.I am trying to figure out how to correctly format the SELECT filter to feed user.identity.name to the SELECT statement as a filter. ... or if there is an alternative way.

View 4 Replies

ADO.NET :: Show Identity Value Before Insert?

Mar 9, 2011

I have a registration page that must contain a user id label. When a user tries to register, the label on the page should show the identity value for the registration before completion. How to do this?

View 1 Replies

C# - How To Insert A Copy Of A Row (with A New Identity) Using LINQ To SQL

Feb 16, 2011

I have a number of tables that together make up a "Test" that somebody can take. There are multiple types (scripts) of Test a person can take. I'm working on an Edit function that will allow somebody to edit the Test Questions. I want these edited questions to show up on all new Tests of that type, but still show the old questions when viewing past test scores.

To do this each "Test" has a TestId auto-increment identity (along with its name). When a test is edited I want to make a copy of the test with a new TestId and present the questions for editing.

So what is the best way to make the copy and insert it into my table using LINQ to SQL? This:

DataContext db = new DataContext(ConnectionString);
//Copy old test into identical new test but with a different script ID
var oldScript = db.TestScripts.Single(ds => ds.TestScriptId == oldScriptID);
var newScript = oldScript;

of course tells me that I Cannot add an entity that already exists.

Is the only way to do this to go through every column in the TestScript and copy it manually, then insert it, and the database will give it a new Id?

View 3 Replies

MVC :: Cannot Insert Explicit Value For Identity Column In Table

Jun 16, 2010

Following the MVC1 vers of Nerddinner, but using 2010 and MVC2. Never seen this error. Looked in controller, model, view. Where does MVC pass the identity value, and how to stop it? I have never had to set IDENTITY_INSERT in any app before.

View 2 Replies

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

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:


View 6 Replies

SQL Server :: Error: Cannot Insert Explicit Value Fir Identity Column?

Mar 8, 2011

I have an insert table with identity specification set. And I getthis error. I'm using a stored procedure to store it. How do I correct it. I'm also using a details view on my insert page.

Exception Details: System.Data.SqlClient.SqlException: Cannot insert explicit value for identity column in table 'Insert' when IDENTITY_INSERT is set to OFF.

View 4 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:


View 6 Replies

How To Insert The Value That Is Not In Textbox Into Database Which Is Primary Key For Table Without Identity Column

Dec 21, 2010

i have created a web form, where i have 3 textboxes into a table and one submit button.

i would like to store values from the textboxes into my database (sql server) when i click the submit button.

but how to insert the value that is not in textbox into database which is primary key for table without identity column.

View 11 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

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:


View 6 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:



BLL layer 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

DataSource Controls :: Use Dataset To Display Sum Where User= User.identity.name(not Use Gridvew, Or Formview)?

Oct 27, 2010

i want to use dataset , or any thing ... to display Sum * where user= user.identity.name(not use gridvew, or formview) because i have more then 100 columns . i m newbie. realy , 1 month, it not solve, sometime , i want to give up

View 3 Replies


Mar 2, 2010

I have created a web services (WCF) and i have a webmethod that return a string that string is a HTTPCONTEXT.USER.IDENTITY.USER unfortunately it does not return any value.

View 9 Replies

DataSource Controls :: FormView InsertItem Return Scope_Identity?

Sep 24, 2010

I've looked all over for this answer and had to resort to several resources. I wanted to post this here because it was so hard for me to find a simple example. If it exist other places then please excuse my post and put references to it on a reply.

So, How do I return the Primary Key Identity when I click the control with the 'Insert' command on a FormView? (With very least minimal code) Help me if there's a quicker way.

<SqlDatasource ID="sqlSource">
<InsertCommand = "INSERT INTO ... ; SELECT @ID = Scope_Identity()">
<asp:Parameter Name="ID" Direction="Output" Type="Int32" />

Protected Sub sqlSource_Inserted()
Dim cmd as System.Data.Common.DbCommand = e.command
Dim strID as String
sqlSource.InsertParameters("ID").DefaultValue = cmd.Parameters("@ID").Value.ToString()
strID = sqlSource.InsertParameters("ID").DefaultValue.ToString()
lblResults.Text = strID
End Sub

View 1 Replies

Forms Data Controls :: Getting Value From A Label In Formview With Singlerow Return?

Oct 3, 2010

getting ans using data in my example.:first I would like to tell that sqldatasource return only one row.


View 2 Replies

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