DataSource Controls :: Why Does Cmd.ExecuteNonQuery() Return -1

Mar 3, 2010

I have created a stored procedure that reset my tables' identity value. The store procedure works fine when I didrectly run it in my ms sql server 2008. It reset my table Identity value However, when I call it from my function reset, it returns -1, and does not reset my table identitity value. The function to restet my identity value is:

[Code]....

My stored procedure is

[Code]....

To call the the function:

Dim result
As
Integer = util.resetTableIdentity("myTable", "id", 60)
util.print(result)

I got result is -1, and it does ot reset my table identity. Why? How to resove it?

View 4 Replies


Similar Messages:

ADO.NET :: ExecuteNonQuery Trimming Return Parameter Value?

Sep 6, 2010

I am observing a rather strange behavior. I have a procedure which selects a field from a matching record and returns it. The procedure works as expected returning proper values, when I execute the procedure from Visual Studio Server Explorer tab. The procedure is

[Code]....

This is being called from the DAL as follows:

[Code]....

The problem is if @ReturnValue is EAE then cmd.Parameter[outputParameterKey].Value is giving the value "E". If @ReturnValue is "Sassyboy" it is giving "S". why this behavior?

View 1 Replies

Web Forms :: Return Scalar Value Using ExecuteNonQuery

Apr 27, 2016

I used this code it’s worked. But I want when Id exist then output any parameter equal 1 else 0. because I have two button Add and Continue.  

CREATE PROCEDURE InsertName
@Id INT = NULL
@Name VARCHAR(50)= ''
as
BEGIN
IF NOT EXISTS(SELECT Count(Id) FROM ParsonTable WHERE Id = @Id) OR @Id IS NULL

[Code] ....

View 1 Replies

Web Forms :: Difference Between Return Value Of ExecuteNonQuery And ExecuteScalar

Oct 6, 2012

I use below code for my button event

int Result = _cmd.ExecuteNonQuery();
if (Result > 0)
{
Session["Login"] = true;
Response.Redirect("~/Managers.aspx?BehCode=" + Server.UrlEncode(TextBox1.Text));
}

But it didn't work it didn't go to managers.aspx page but when I replace code with below code it worked correctly it go to managers.aspx

int count = Convert.ToInt32(_cmd.ExecuteScalar());
if (count > 0)
{
Session["Login"] = true;
Response.Redirect("Managers.aspx?BehCode=" + Server.UrlEncode(Txtbeh.Text));
}

Why this happen whats exact different between two code?

View 1 Replies

DataSource Controls :: Benefits Of Using SqlCommand.ExecuteNonQuery Instead Of â€

Mar 29, 2010

[Code]....

is used for update, insert and delete operations.Besides the fact

View 3 Replies

DataSource Controls :: Table Isn't Updating Using Executenonquery?

Jan 20, 2010

I have stepped through this code to test it and I am puzzled as to why the update isn't going through to the DB. When I run the SQL statement in SQL editor it updates fine. All variables are getting the proper values when I step through.

[Code]....

View 5 Replies

DataSource Controls :: ExecuteNonQuery And Stored Procedure?

Jun 28, 2010

Im using above to makes sure that record is inserted to the SQL database before executing another function, but for some reason even if the record is NOT inserted other function has been called.(Other function is t update a Flag)

look at my code below and see where it goes wrong??

Part of the .Net Code
=============================================================
Private Sub GetAndInsert()[code]....

I have a feeling it could be that Rolling back is done in both .NET and SP??

View 2 Replies

DataSource Controls :: ExecuteNonQuery - Declare And Execute All On One Line?

Apr 14, 2010

I'm looking for a way of being able to declare and execute a SqlCommand all on one line. At the moment I do something like:

Dim Cmd as New SqlCommand("....", Conn)
Cmd.ExecuteNonQuery

How can I do something like:

(New SqlCommand("....", Conn)).ExecuteNonQuery

View 3 Replies

DataSource Controls :: ExecuteNonQuery Requires An Open And Available Connection?

Feb 4, 2010

I've a web form named contest, where users are to register for it. When the register is clicked on, details entered by the user will be saved into the database, but before it will check if the user has already participated in the contest (using AJAX). If the user has already participated, the button will be disabled. The problem is there is an error when I click on the register button.

The error:

ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.

Here's the codes I use:

[Code]....

View 7 Replies

DataSource Controls :: To Write Safe Code Sqlcommand.ExecuteNonquery?

Jan 6, 2010

how to write code for database transaction(eg; Insert,delete,update) i want to write a better code

eg:sqlcommand.Commandtext="some sql insert query";

sqlcommand.parameter.Add(new sqlparameter("@cmdname","someValue"));


sqlcommand.ExecuteNonquery();

how to write the above code in better and safe way, i am expecting .net master also answer this question

put his view(pros and cons)

View 2 Replies

DataSource Controls :: Return Value From Sql In GridView?

Aug 28, 2010

I have textbox for searching a Names in My database. I return the information from the Select Statement in GridView, but i want to know the number of affected rows. How to do that?

View 3 Replies

DataSource Controls :: How To Return A Single Row Where There Is A One To Many Relationship

Jun 23, 2010

I have 2 tables. Table_A has one to many relationship with Table_B.

For example. Table_A has an ApplicantKey and in Table_B I am storing (Resume_name and CoverLetter_name for the Applicant). Joined by ApplicantKey

Now when I join them and execute the query obviously it returns me two rows. But what I want is that it should return only one row with Columns like Resume_name, CoverLetter_Name

View 2 Replies

DataSource Controls :: How To Access The Return Value Of The SQLDataReade

Feb 15, 2010

accessing the return value of the SQLDataReader. My code is below. Actually the variable that I assigned my SQLDatareader object to is say HasRows property=true. But I am having trouble accessing the return value. And I get the error when I use the following code .Text =SQLDataReader("Contact Name").ToString I get the following error message: Invalid attempt to read when no data is present.

con = New SqlConnection(ConfigurationManager.ConnectionStrings("Connect").ConnectionString)
Dim getDirectorsCMD As SqlCommand = New SqlCommand("dbo.spGetDirector", con)
getDirectorsCMD.CommandType = CommandType.StoredProcedure
Dim myParm As SqlParameter = getDirectorsCMD.Parameters.Add("@BuildingTID", SqlDbType.Int, 15)
myParm.Value = ddlBuilding.SelectedValue
[code]...

View 3 Replies

DataSource Controls :: Return ID Of Inserted Record

Jan 12, 2010

I followed this BRILLIANT article and found out how to make a data layer, i just need the insert method in this code to return the ID of the record inserted.

For example, when the user captures the details, the save button is clicked, i will want to display in a label "Your Reference Number is "

try and have look at the article so you will understand how the code is, so it will not be hard to edit my code.

[URL]

View 7 Replies

DataSource Controls :: Return Range Of Dates

Feb 25, 2010

I have this query:

[Code]....

I want to select dates that also fallin the range. Heres the scenario: I have an event from 01/20/2010 TO 01/25/2010. So right now it would only return a date of 01/20/2010. How could I return 01/20/2010, 01/21/2010 , 01/22/2010, 01/23/2010, 01/24/2010, 01/25/2010? Mind you only a start and end date are in the database.

View 3 Replies

DataSource Controls :: Return New ID From LINQ InsertOnSubmit?

Jan 21, 2010

I have an autoincrement ID on some table.I need to know what is the ID of the new row when I add the object using InsertOnSubmit, but this method returns void.What is the common way of doing this.

View 1 Replies

DataSource Controls :: Return First Value From A Linq Query?

Mar 12, 2010

Is there a way opf getting the first value from a linq query so for example

[Code]....

View 2 Replies

DataSource Controls :: Return String Value From The Function?

Mar 7, 2010

i try to return string value from the function i wrote for getting string value from the table for that i havecommon stored procedure

public string getdata(string str)
{
string datanew;

[code]...

View 2 Replies

DataSource Controls :: How To Retrieve The Return Value From Stored Procedure

Jun 16, 2010

i want to retrieve the return value of following stored procedure in my Data Access Layer of ASP

CREATE PROCEDURE Procedure_login

View 3 Replies

DataSource Controls :: Return Values From Select Statement?

Feb 8, 2011

I have a select statement in a stored procedure and want to be able to retrieve the key column value (PRODUCTID)and return it as Output when Select statement is executed on input Parameter (NAME).

addition, return two further output values (COST,TOTAL).

note the grid control expects to receive all values at once! so i need to get out these values at the same instance of execution.

Select productID,COST,QUANTITY,NAME,TOTAL,DATE
FROM PRODUCTS
WHERE NAME=@NAME

View 2 Replies

DataSource Controls :: SQL Statement - Don't Want To Return Duplicate Columns

Mar 11, 2010

I have the following simple stored procedure:

ALTER PROCEDURE GetadiByPhiNo

@PhiNo int

SELECT adirefno, adidescription

FROM aditable

WHERE adiphino = @PhiNo

Here is an example of data returned:

1 Skin diesease

2 Cough

3 Cough

4 Rash

You notice "Cough" is in the adidescription column twice. I would like to return only one row for adidescription with the same value. So what I want returned is this:

1 Skin diesease

2 Cough

4 Rash

View 8 Replies

DataSource Controls :: Return Value From Stored Procedure To C# Code Behind?

Mar 16, 2010

So I am getting this error message:

Cannot implicitly convert type 'System.Data.SqlClient.SqlParameter' to 'string' I have a stored procedure on SQL 2000 returning an email from a database table (aspnet_Membership). The email type from the table is nvarchar. I have a method (in C# in the code behind) that gets that value. But the debugger doesn't like the last line:

return returnEmail; // returnEmail is a string variable we created to capture the stored procedure's return value

I've tried doing returnEmail.toString() in several places, but still get the same error message for the last line of code (returning the email).

This is the stored procedure:

View 3 Replies

DataSource Controls :: How To Return Variables From Stored Procedure

Feb 1, 2010

I have a stored procedure which returns a value to state if the userlogin is valid. but i want to return the data and store it in a data session as i will require the user details in the checkout page.

is it best to get individual parameters out of the stored procedure then assign the variables to a datatable which is then assigned to session Or how can i get all the details returned from the stored procedure for the table? not sure which would be the most effective solution?

View 9 Replies

DataSource Controls :: Return Unique Rows : T-SQL Query

Jun 11, 2010

I have an SQL database table like the following:

ID // Code // Shape

The ID is the integer identifier.

On one line the Code may be OX01 and shape Hexagon for example

Then the next line the code is still OX01 but the shape is Triangle.

What I want to do is be able to pull back data for every line that is equal to a unique Code column. in the above example OX01 Hexagon would be returned but not OX01 Triangle.

I've tried using SELECT DISTINCT but it brings back all records and doesn't filter them correctly.

I've considered having another column which could have Child/Parent data so that only the parent is returned but i'm sure there must be a better way of doing this.

View 2 Replies

DataSource Controls :: Can Capture Return Value From A SQL By Using SqlConnection SqlCommand

Apr 15, 2010

can capture return value from a SQL by using SqlConnection SqlCommand

[Code]....

View 3 Replies







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