DataSource Controls :: Store Procedure Is Returning -1 Even Though It Is Successfully Inserting/updating Record

Jan 29, 2010

My insert is adding a record to the database in the call to the stored procedure in SQL Server, but a -1 is returned - Shouldn't it return 0 if the insert/update was successful?

Result = myCommand.ExecuteNonQuery();

View 3 Replies


Similar Messages:

DataSource Controls :: Getting The PK ID Of The Newly Created Record After Inserting A New Record?

Dec 20, 2010

I am creating an album using the following stored procedure, which returns the primary key for the newly created record:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[fpa_sp_albums_update_insert]
@album_id int,
@album_name nvarchar (50),
@album_descr nvarchar(250),
@album_img_cover_id_FK int,
@album_creation_date date
AS
If @album_id > 0
UPDATE [fpa_albums]
SET
album_name=@album_name,
album_descr= @album_descr,
album_img_cover_id_FK = @album_img_cover_id_FK,
album_creation_date = @album_creation_date
Where ((album_id = @album_id))
Else
INSERT INTO [fpa_albums] (
album_name,
album_descr,
album_img_cover_id_FK,
album_creation_date)
VALUES (
@album_name,
@album_descr,
@album_img_cover_id_FK,
@album_creation_date)
Return SCOPE_IDENTITY();

I execute the above stored procedure using the SQLHELPER. The VB.NET code for the page is as follows:

[Code]....

However, the createdAlbumID always shows -1 instead of the id for the newly created album.

View 1 Replies

DataSource Controls :: Stored Procedure Not Returning Value

May 15, 2010

I call this stored procedure with a dataset. It always returns a 0 but should return a 1 or 2. Does anybody know why it isn't returning a 1 or 2.

ALTER PROCEDURE dbo.sp_InsertLinkVote
@LinkId int,
@LinkVoter nvarchar(50),
@LinkVotesDateTime datetime,
@LinkVotesGoodBad bit
AS
/* SET NOCOUNT ON */
 
If EXISTS
(SELECT
*
FROM
LinkVotes
WHERE
LinkId=@LinkId
and
LinkVoter = @LinkVoter )RETURN
1
ELSE
INSERT INTO
dbo.LinkVotes (LinkId,LinkVoter,LinkVotesDateTime,LinkVotesGoodBad)VALUES
(@LinkId,@LinkVoter,@LinkVotesDateTime,@LinkVotesGoodBad)RETURN
2

Here is were a call it in my code behind.
Dim VoteCheck
As
Integer
Dim InsertVote
As
New DataSetStoredProceduresTableAdapters.QueriesTableAdapter
VoteCheck = InsertVote.sp_InsertLinkVote(LinkId, User.Identity.Name, DateAndTime. Now,
True)
'0 is a good vote.
If VoteCheck = 0
Then

It seems to insert and not insert correctly, I just cannot get it to return the correct value.

View 4 Replies

DataSource Controls :: Returning Value From Stored Procedure

Jun 23, 2010

I am developing a page in ASP.Net where I have the user enter a letter into a textbox. They then click a submit button and I all of the userids that start with that letter are to be displayed. So I need the SP to go through the database and match first letters with what was entered. Here is what I have as my code for the SP:

CREATE PROCEDURE dbo.exp2 @testchar Char(1)
declare @flag as char(2)
set @flag = @testchar + '%'
select userid
from ex_database
where userid like @flag

View 6 Replies

DataSource Controls :: Returning Null Value From Procedure?

Jun 17, 2010

[Code]....

iam using asp.net2.0 with c# with sql server 2000 when iam executing the procedure in local system it is working fine.but when iam executing in client system procedure returns null value, i have checked all connection string , and session value all are working

View 1 Replies

DataSource Controls :: Procedure Returning Values From Page?

Apr 29, 2010

In Login page, i make use of the following procedure:

ALTER PROCEDURE dbo.logincheck

View 4 Replies

DataSource Controls :: Stored Procedure Returning Error?

May 24, 2010

Im trying use a storedprocedure where depending on the status of the room if ='Vacant' And checkIn =date and the result will be put in a gridview, but i kept returning an error that says, "Conversion failed when convertng datetime from character string". Heres the code.

Caller:

[Code]....

Stored Procedure:

[Code]....

GridviewFiller:

[Code]....

View 7 Replies

DataSource Controls :: Get The Inserting ID Out Of The Record Using Scope_identity

Jun 9, 2010

Im trying to get the ID out of the record that i'm inserting using scope_identity. I've add the following line of code to the Insert statements in the sqldatasource - SET @insID = Scope_Identity() I've add the following line to the Insert parameter list

asp:Parameter
Name="insID"
Type="Int32"
Direction="Output"

I now want to insert a number records into the database using the following:

Dim insID As Object = e.Command.Parameters("@insID").Value ' gets out latest ID
Dim ordernumber As String = "CX" & insID.ToString & DateTime.Now.DayOfYear.ToString
sqlOrders.InsertParameters("orderNumber").DefaultValue = ordernumber
sqlOrders.InsertParameters("orderDate").DefaultValue = DateTime.Now
sqlOrders.InsertParameters("customerID").DefaultValue = userID
sqlOrders.InsertParameters("productID").DefaultValue = productID
sqlOrders.InsertParameters("totalPrice").DefaultValue = "0.00"
sqlOrders.InsertParameters("status").DefaultValue = "Paid"

I currently have this code in the SQLDataSource_Inserting sub but the first line only works once the record is inserted. How can i get the ID out as im inserting the parameters?

View 3 Replies

DataSource Controls :: Inserting New Record Error?

Jan 14, 2010

I have the logged-in user's Guid stored in a session variable. My understanding is that when the Guid is passed to the session variable it becomes a string. When I use the detailsview control I have to convert the session variable back to a guid and I've been doing it like this and it seems to work fine:

e.values("UserId") = session("LoggedInUserId")
Dim UserId as Guid = New Guid()

When I try to use the Insert() command after the following:

SqlDataSource3.InsertParameters("UserId").DefaultValue = Session("LoggedInUserId")

I get an "InvalidCastException" error with the comment "Conversion from type 'Guid' to type 'String' is not valid." I'm assuming the session variable needs to be converted to a type Guid since that's what I've had to do with the Detailsview control. I've tried a few different ways of converting the session variable back to a Guid so the insert command will work, but no matter which method of conversion I try I get errors such as "value of type system.guid cannot be converted to 'string'. I'm confused because I thought I was supposed to convert it from a string to a Guid. The "UserId" parameter is a non-primary key uniqueidentifier in the database.

View 2 Replies

DataSource Controls :: Stored Procedure And Function Returning Same Shape

Jan 26, 2010

I have problem with a stored procedure and function that return the same shape, but as they are different methods LINQ won' t let me cast between the two. Please see code for the two SPROCs below (This is actually simplified to represent the problem, so please don't spend lots of time explaining alternative ways of writing the function/sproc.)

Table Valued Function
"getCategories()"
SELECT categoryName, categoryID FROM categories
SPROC "getUnusedCategories"
SELECT categoryName, categoryID FROM CategoryInstances cI
FROM dbo.SMAN_getCategories(@SiteMANID, @SectionID) c
LEFT JOIN @EntityResultsTable er

View 2 Replies

DataSource Controls :: Returning String Value Using Stored Procedure And Linq

Feb 7, 2010

I am having problems returning a string value through a stored procedure/linq to a label. Everything works fine if I return an integer value but I cant get a string value to bind to a label. I get the error message

Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value,
NumberFormatInfo NumberFormat) +201
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +66
[InvalidCastException: String "System.Data.Linq.SqlClient.SqlPr" to 'Integer' is invalid‚]

This is the stored procedure
ALTER PROCEDURE test
AS
Select ProductName
From Products

This is the vb page
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim db As New DataClassesDataContext
Dim product As Integer = db.test.ToString
Label1.Text = product
End Sub

This is the aspx page
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</form>

View 1 Replies

DataSource Controls :: How To Start At A Specific Record And Returning Only The Next 5 Records With T-SQL Command

May 11, 2010

How to start at a specific record and returning only the next 5 records with T-SQL command

[Code]....

That is my concatenated SQL statement but it obviously does not work because it only looks at the top 5 records in the entire table instead of what I intended which would be to look at the top 5 records starting with the record where PostNumber equals the value of lastPost. I have been searching for a T-SQL statement that will allow me to do this but I can't find one.

View 2 Replies

DataSource Controls :: Returning Single String Value Using Linq And Stored Procedure

Jun 21, 2010

I can return single integer values when using stored procedures with Linq but I cant get single string values returned.

View 2 Replies

DataSource Controls :: Eliminate Returning Of Empty Table From Stored Procedure

Jul 12, 2010

I have a Procedure which should return only 1 Record on selecting record according to Priority.

BEGIN
DECLARE @Accounts nvarchar(MAX)
SELECT @Accounts = ISNULL([map_user_modules].[Accounts], '') FROM [map_user_modules]
WHERE [map_user_modules].[id_user] = 231 AND [map_user_modules].[id_module] = 5
IF ((@Accounts = '') OR (@Accounts = 'All'))
SELECT @Accounts = null

BEGIN
Select @@ROWCOUNT as Priority2
END
IF @@ROWCOUNT = 1
BEGIN
Return
END

BEGIN
Select @@ROWCOUNT as Priority3
END
IF @@ROWCOUNT = 1
BEGIN
Return
END

BEGIN
Select @@ROWCOUNT as Priority4
END
IF @@ROWCOUNT = 1
BEGIN
Return
END

In the above statement Suppose we take a scenario where Select @@ROWCOUNT as Priority3 is executed, I get two tables returned, One is the Table returned by Select @@ROWCOUNT as Priority3 and the other is the Table returned by Select @@ROWCOUNT as Priority2 which has no Records. How can I eliminate the Empty table that returns no records.

View 1 Replies

DataSource Controls :: Stored Procedure Returning Null But Executes At SQL Server

Jul 1, 2010

I am using
SqlHelper.ExecuteDataset(MyConnectionString, CommandType.StoredProcedure, "GetInformation", new SqlParameter("@ID", ID));

In my stored Procedure, I am doing a lot of calculation with joins and it took 19 sec to execute at my sql Server 2008. My application had been working perfectly for 5 days but now as database increases, I found a problem that my connection is breaking at that point. At Sql Server, it execute fine but when I add a breakpoint and watch the stored procedure is returning null.

View 2 Replies

DataSource Controls :: Sql Server Deadlock / Only Inserting/updating Data Into A Table

Jun 11, 2010

I m getting following error in my eventvwr . I couldnt find reasons of the following error.

"Transaction (Process ID 110) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction. "

The only thing my page is doing is inserting/updating data into a table in sql and the thing I can think of is because multiple users are using the same page to insert/update data? Will that cause deadlock?

View 4 Replies

DataSource Controls :: Ado.net Dataservices Inserting A Record (with Inheritance Applied)

May 23, 2010

I have an entity model, in which I have a table per type inheritance. Is it possible to perform an insert using ado.net dataservice and asp.net ajax library? I was trying the following client code :

dataContext.insertEntity(childData, "Parent");

I was getting this response from server : Error processing request stream. Type information must be specified for types that take part in inheritance.

View 1 Replies

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 :: Store Procedure SQL Server?

Feb 8, 2010

I had a little problem with the value that one of my SPs returns. In my SP, I create some temporary tables to store certain data from multiple tables and contains some queries for an advanced calculationBut precisely yesterday, the value that the SP returns was incorrect. I tried to look at the SP and the data again and everything was OK, but not the result from the SP.And what the heck!!..today the value is totally right ...I truly have no idea what's wrong with the SP..Is there anyone knows what the root of cause is?

View 4 Replies

DataSource Controls :: Looping Through Textbox Values And Inserting Into SQL Server Via Stored Procedure

May 9, 2010

I have a database table as follows:

[Code]....

This table receives data from my web application via a stored procedure, snippet pasted below:

[Code]....

In my quote.aspx page, I have a wizard control that collects numerous data points. In one of the wizard steps, I have 20 textbox controls for PartNumbers and 20 textbox controls for respective Quantity.

Question:How do I write a for..each loop that checks for values in my Part Number and Quantity fields and inserts them via my SQLDataSource?

View 5 Replies

DataSource Controls :: How To Execute Sql Dynamically In Store Procedure

Apr 14, 2010

I have a sql which the data read from the store procedure is very dynamic.

i have finish the first part of the sql in stored procedure but having problem in executing it.

[Code]....

How do i use EXECUTE SP_EXECUTESQL to do this??

View 2 Replies

DataSource Controls :: How To Get Store Procedure Output Into Table

May 19, 2010

I want to execute a Store Procedure and then get the Output in one table. However I am not getting the query. I want something like this execute 'Stored procedure name' 'param1','param2','param3' and then get the result into some table. Is this possible?
select * into #table from (execute 'Stored procedure name' 'param1','param2','param3')

View 1 Replies

DataSource Controls :: Help With Registration Page Use Store Procedure

Jan 1, 2010

storeprocedure code:

ALTER PROCEDURE sp_CheckForDuplicates
(
@UserName VARCHAR(50) = NULL,
@FirstName VARCHAR(50) = NULL,

-----------------------------
Error show :if (objReturnPara>0)

[Code]....

operator '>' cannot be applied to operands of type 'object' and 'int'

operator '>' cannot be applied to operands of type 'object' and 'int'

View 14 Replies

DataSource Controls :: Dynamically Change Store Procedure?

May 7, 2010

I am using SqlDataSource control to query my data via store procedure. Based on which option the user picked from the RadioButtonList control, I want to dynamically at run time to choose which store procedure gets executed. How do I do this? I am already using Query String for my parapmeters. I can could use this for the store procedure as well. The problem is, how do I get the SelectCommand to pick the store procedure name from the parameter passed in the URL?

View 7 Replies

DataSource Controls :: Create Store Procedure Not Working?

Mar 10, 2010

When I try to create a stored proc in SQL Server Express 2008 by right clicking on the Stored Procedures folder of my database and selecting New Stored Procedure, then attempt to save, it saves the procedure as a SQL query in the projects folder instead of saving it as a stored procedure in the Stored Procedures folder of my database.

View 2 Replies







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