DataSource Controls :: Pass In As An Insert Parameter For SQLds2 The Scope_identity Of The Insert Of SQLds1

Jan 12, 2010

I am trying to pass in as an insert parameter for SQLds2 the scope_identity of the insert of SQLds1.

Exception Details: System.InvalidOperationException: Error executing 'InsertCommand' in SqlDataSource 'SqlDataSource1'. Ensure the command accepts the following parameters: @Name1, @NewId

[Code]....

View 4 Replies


Similar Messages:

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 :: Multi Insert Query Using Scope_identity Not Working

Jul 10, 2010

I'm trying to create multi insert query in single stored procedure along with scope_identity variable. while execute the aspx page getting error "Procedure 'sp_seller_ins' expects parameter'@new1', which was not supplied." I have created stored procedure:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_seller_ins]
@txt_n_properity VARCHAR(50),
@txt_t_properity VARCHAR(50),
@txt_prop_for VARCHAR(50),
@txt_flat_no VARCHAR(50),
@txt_loc_country VARCHAR(50),
@txt_loc_state VARCHAR(50),
@txt_loc_district VARCHAR(50),
@txt_loc_town VARCHAR(50),
@txt_loc_area VARCHAR(50),
@txt_loc_locality VARCHAR(50)
AS
BEGIN
declare @new1 int
declare @new2 int
INSERT INTO dbo.sel_pro_details( nature_property, type_property, property_for, flat_no) VALUES ( @txt_n_properity, @txt_t_properity, @txt_prop_for, @txt_flat_no);
set @new1 = scope_identity()
INSERT INTO dbo.sel_loc_details( country, state, district, town, area, locality, pro_details_id) VALUES (@txt_loc_country, @txt_loc_state, @txt_loc_district, @txt_loc_town, @txt_loc_area, @txt_loc_locality, @new1);
set @new2 = scope_identity()
end
code behind aspx page
sqlconn mySql = new sqlconn();
mySql.CreateConn();
mySql.Command = mySql.Connection.CreateCommand();
mySql.Command.CommandType = System.Data.CommandType.StoredProcedure;
mySql.Command.CommandText = "sp_seller_ins";
mySql.Command.Parameters.Add("@txt_n_properity", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_n_properity"].Value = txt_n_properity.Text;
mySql.Command.Parameters.Add("@txt_t_properity", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_t_properity"].Value = txt_t_properity.Text;
mySql.Command.Parameters.Add("@txt_prop_for", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_prop_for"].Value = txt_prop_for.Text;
mySql.Command.Parameters.Add("@txt_flat_no", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_flat_no"].Value = txt_flat_no.Text;
mySql.Command.Parameters.Add("@txt_loc_country", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_loc_country"].Value = txt_loc_country.Text;
mySql.Command.Parameters.Add("@txt_loc_state", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_loc_state"].Value = txt_loc_state.Text;
mySql.Command.Parameters.Add("@txt_loc_district", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_loc_district"].Value = txt_loc_district.Text;
mySql.Command.Parameters.Add("@txt_loc_town", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_loc_town"].Value =txt_loc_town.Text;
mySql.Command.Parameters.Add("@txt_loc_area", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_loc_area"].Value =txt_loc_area.Text;
mySql.Command.Parameters.Add("@txt_loc_locality", SqlDbType.VarChar);
mySql.Command.Parameters["@txt_loc_locality"].Value =txt_loc_locality.Text;
mySql.Command.ExecuteNonQuery();
mySql.Command.Dispose();
mySql.Connection.Close();
mySql.CloseConn();

View 1 Replies

DataSource Controls :: SCOPE_IDENTITY() - Insert A New Record And Get The Value From The New OrderID Column

Jun 27, 2010

I have an orders table with a column names orderID. What I want to do is insert a new record and get the value from the new orderID column. The orderID is my Primary key. The Insert SQL I have now is -

INSERT INTO orders
(creditAutorizarionNumber, OrderName, OrderPersonPhone, OrderPersonEmail)
VALUES (@creditAutorizarionNumber,@OrderName,@OrderPersonPhone,@OrderPersonEmail)

How do I write the query to get the newly entered orderID ?

View 6 Replies

DataSource Controls :: Set Null Value To SqlDataSource Insert Parameter?

Dec 21, 2010

this is my html code [Code]....

i need to set null value to SqlDataSource Insert Parameter at runtime

i am used this code

[Code]....

View 5 Replies

How To Pass Parameter Back From Web Service If An Insert To A Database Successfull

Oct 29, 2010

I have a web form and I use jQuery/AJAX/JASON to send objects to a web service using

$.ajax({
type: "POST",
url: "SynchroniseCustomers.asmx/synchroniseCustomers",
data: JSON.stringify(customerObj),
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (xhr, status) {},
success: function (msg) {}
});

From the web service I want to check if the insert into the database was successfull, return a variable with an ID and pass this ID to a function. In the object I have the ID so I could have

success: function (msg) {deleteCustomer(ID);}

But this only checks if the data was passed to my method in the web service? I have followed this example http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/ and in the class Person I get a message back from the database server telling me if the insert was successfull or not so like

if (successfull)
{
return ID;
}

is there a way to get this ID back to the web form and use this in a variable?

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

ADO.NET :: Using SCOPE_IDENTITY() To Retrieve The Id Of Last SQL Insert

Sep 27, 2010

I need to get the id of a record created so that I can store that ifnormation in another SQL table. A snipet of my c#code is as follows:

string insertSql = "INSERT INTO [Group] ([userid], [groupname]) VALUES (@userid, @groupname); SET @groupid = SCOPE_IDENTITY()";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand(insertSql, myConnection);
myCommand.Parameters.AddWithValue("@userid", currentUserId);
myCommand.Parameters.AddWithValue("@groupname", groupTextBox1.Text);
SqlParameter groupidParameter = new SqlParameter("@groupid", SqlDbType.Int);
groupidParameter.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(groupidParameter);
myCommand.ExecuteNonQuery();
myCommand.ExecuteNonQuery();
gid = (int)groupidParameter.Value;
myConnection.Close();
}

The problem is that I am not getting the @groupid from the SET @groupid = SCOPE_IDENTITY() that is appended to the INSERT statement. The groupid in the SQL table is the Key of type uniqueidentifier

View 3 Replies

C# - Getting SCOPE_IDENTITY From SQL Server On Insert

Feb 7, 2011

I guess it is too late and I'm too tired to see what I'm doing wrong. Here is what I'm trying:

int imageId = imageDal.AddImage(new SqlParameter[]
{
new SqlParameter("@IMAGE_ID",
SqlDbType.Int, Int32.MaxValue, ParameterDirection.Output,
true, 0, 0,"IMAGE_ID", DataRowVersion.Current,DBNull.Value),
new SqlParameter("@IMAGE",
SqlDbType.Image, 11, ParameterDirection.Input,
true, 0, 0,"IMAGE", DataRowVersion.Current,image)
});
public int AddImage(SqlParameter[] spParams)
{
SqlHelper.ExecuteNonQuery(BaseDAL.ConnectionStringImages, INSERT_IMAGE_SQL, spParams);
return Convert.ToInt32(spParams[0].Value);
}
Stored Procedure:
[dbo].[sp_insert_image]
-- Add the parameters for the stored procedure here
@IMAGE_ID int OUT,
@IMAGE image
AS
BEGIN
INSERT INTO images
(IMAGE)
VALUES
(@IMAGE)
SELECT @IMAGE_ID = SCOPE_IDENTITY();
END
GO

I get DBNull as spParams[0].Value. I've tried setting value of @IMAGE_ID to a constant in my stored procedure yet it didn't change anything so the problem isn't with my stored procedure (that is what I think). When I execute the procedure from sql management studio, I see the inserted_id returning..

View 2 Replies

DataSource Controls :: Insert In To 2 Tables Using A SQL And Details View Insert Functionality?

Aug 12, 2010

I do have a details view, which insert data to a database table using SQL Datasource. Now i need the data to be inserted in to 2 tables instead of one.

View 1 Replies

DataSource Controls :: Sql Insert Failing On Detailsview Insert Or Update?

Mar 6, 2010

I am using 1 textbox with a Ajax Calendar extender to allow my user's to select a date graphically (exp: 12/15/2009). I have another textbox for the hour and minutes in military time(exp: 15:30). I think i have the code to grab the data from the 2 textbox's and combine them to be inserted into the field (exp: 12/15/2009 15:30). Here is my insert code for the Field:

[Code]....

However unless I make all the fields Nullable the insert fails, on top of that none of the other field that I have selected on the Detailsview Insert or Edit are inserted into there fields. Half of my fields have to be non-null values. So how do I fix this?

I can supply additional vb code and the aspx code if needed.

This is the error I'm getting: Cannot insert the value NULL into column 'Operation_type', table '/GAOSDB.MDF.dbo.BC_Perf_Log'; column does not allow nulls. INSERT fails. The statement has been terminated.'

This is the first non-null column.

I need to get this figured out because I have 30 other web pages that will be utilizing the same approach.

View 4 Replies

DataSource Controls :: Insert A New Record, Then Using That New Records PK ID In Another Insert

Jun 30, 2010

Conseptually what I'm doing is simple, and technically it may even be simple, but I'm still rusty. Here's what I'm trying to do:

I have a webform that allows the user to enter a new record, and in there I have also included a couple FileUpload controls. Upon clicking the "Save" button, I'm saving the details entered into one table (ITEMS), and also inserting the FileUpload details (path, id, upload_user) into another table ATTACHMNTS). Because one ITEM can have many attachments, I needed to split the tables up. So on save, I need to save the ITEM, save the ATTACHMENT, and then also put the ITEM_ID in the ATTACHMENT table. I'm second guessing myself because I think all I'd have to do is after I do the ITEM insert, do a SELECT MAX on the ITEM table and hold the newest (MAX) id in a variable and then use it in the ATTACHMENTS update. I'm not 100% on this because there IS a chance that someone else could save a few milliseconds later and I'll link the wrong ITEM. See my delima?

View 7 Replies

DataSource Controls :: INSERT Statement For A CSV To Insert Into SQL Express?

Dec 15, 2010

I have a project that I was using Access for but now find I have to change to SQL Express. Well I have no big problem with that but I now find that the SQL Statement I have been using was for OLE and does not work in SQL/Express. I am not even sure anymore if I can dump the entire CSV file in at one time? The statement I was using is below.

[Code]....

Here is my problem. What is the INSERT statement to insert a complete flat (CSV) into SQL Express? OR what method can I use to preform this task?

View 2 Replies

SCOPE_IDENTITY() Returns An Empty String After A Confirmed Insert

Oct 13, 2010

This is completely frustrating and probably embarrassing as well. A while back I posted a similar question and resolved the issue. [URL]...scope_identity The program has been working ever since, until yesterday when as it turns out SCOPE_IDENTITY() started returning an empty string even though a record is being inserted. I am not sure what has changed since the fateful day.

[Code]...

I am hoping that there is something I am just not seeing here. A lot of the information I have seen thus far indicates that there are problems with SCOPE_IDENTITY() but most of those are related to inserting multiple records. As you can see this should be fairly straight forward. The thing that really has got my goat is that it used to work and now it doesn't. If someone could take a look at the above code and comment on any anomalies it would be great. Also I have heard suggestions for switching to ADO.NET and it is beginning to look a lot more attractive every day. But I have a ways to go before making the switch so it is SqlDataSources for now

View 37 Replies

Forms Data Controls :: Setting An Insert Parameter Programatically In Formview?

Mar 21, 2010

I have a formview bound to a sqldatasource control. I want to set one of the insert parameters when I click on one of several buttons (outside the formview).

In my sqlDS I have:

<InsertParameters>
<asp:Parameter
Name="benType"
Type="byte"
/>
<asp:Parameter
Name="benName"
Type="String"
/>
<asp:Parameter
Name="benDesc"
Type="String"
/>
</InsertParameters>

I want to set the "benType" depending on which button I've pressed (I don't want/need it to be visible in the InsertTemplate). I tried adding this line to the codebehind for the button click:

formview1.ChangeMode(FormViewMode.Insert)
formview1_datasource.InsertParameters(0).DefaultValue = 2

This doesn't work...what is the best way to set the insertParameter from outside the formview?

View 6 Replies

Forms Data Controls :: GridView Insert Control Parameter Null Value And Nbsp?

Jan 6, 2010

Basically, the user Selects a row on GV that executes an Insert into a table the GV cell values of the selected row.

The SQL field data type is varchar. If the GV field is Null, the Insert adds the value to the SQL field. How do I keep the @nbsp; from being displayed in the cell of a data control when it is called at a later time? Do I add some more asp to my control parameter? do I add some vb code behind? Here are some relevant code snippets of existing code.

[Code]....

[Code]....

View 3 Replies

Forms Data Controls :: Pass User Id To A Boundfield On Insert?

Feb 15, 2010

I have the following code:

[Code]....

This is placed in the sqldatasource selecting sub. It works well and loads up data from the database based on the @UserId parameter.

I load up the detailsview and it only loads up data from the DB based on the currently logged in user, however i want them to be able to insert some data too.

Anyone know how i can achieve this when they select insert? For starters i having endless parameter problems but i am sure i can sort that out. what i really need is someone to tell me how i can pass the UserId into the USERID text when the details view mode changes to "insert"

I know there is a "mode changed" event, should i be using that?

View 4 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 :: DetailsView EmptyDataTemplate After Insert Defaults To Empty Insert Screen

Jan 27, 2010

In my detailsview, I have an emptydatatemplate set up to allow users to enter new records. The code works. However, once the record is inserted, the detailsview defaults to a standard insert screen. I know this will cause confusion for the users. I would prefer the detailsview to either show in edit mode or a read-only mode. I have used detailsview.changemode and detailsview.currentmode in the custom sub created for the add new button of the emptydatatemplate- neither of which do what I was hoping. It would be even better if when there was no data, it defaulted to the insert screen (which seems like that should be an easy, no-brainer way for .net to function) but it doesn't. Or, I don't know how to accomplish it.

I don't want to force the user to click cancel after inserting an item through the emptydatatemplate just to be able to use the detailsview for other records.

View 2 Replies

Forms Data Controls :: Insert New Blank Rows In A Gridview And Insert Them In Database Multiple At A Time?

Oct 19, 2010

I have grid view in ASP.Net 3.5. I need to add multiple blank rows in a gridview and then have to save them in database. How can I do that in most simplest way?

View 7 Replies

Forms Data Controls :: Insert On Details View Causes Error Cant Insert Null Into Primary Key Field?

May 22, 2010

I am using Visual studio 2010 express and I have a details view databinded to an sql database table. When I use the Insert option on the view it causes an error due to it trying to insert a null into the primary key field. If the Insert function does not create a new primary key entry how is it created?

View 9 Replies

Forms Data Controls :: Insert A Snippet To Change A Hyper Link 'insert' To A Button Image?

Nov 21, 2010

How do I insert a snippet to change a hyper link ' insert' to a button image?

Here is the front page code:

[Code]....

View 4 Replies

Forms Data Controls :: Insert Radio Button Selection  into Sql Server Database  using Parameter?

Nov 7, 2010

how to insert radio button selection into sql server database using parameter.

View 3 Replies

DataSource Controls :: How To Pass Optional Parameter

Apr 22, 2010

I am getting return some data through stored procedure in a asp.net 3.5. Below is the method.

public DataSet GetDataSet(string strConnection,string strSPName, string param1)
{
DataSet ds = dataAccessLayer.getDataSet(strConnection, strSPName);
return ds;
}

In some cases, I have to pass 3-4 parameter. How can we do pass optional parameter here....

View 3 Replies

DataSource Controls :: Pass Default Value To A Sql Parameter?

Sep 23, 2010

I'm trying to pass default value to a sql parameter which is

[Code]....

View 1 Replies







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