Questions tagged [executenonquery]

executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.

From MSDN: You can use the ExecuteNonQuery to perform catalog operations (for example, querying the structure of a database or creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

Although the ExecuteNonQuery does not return any rows, any output parameters or return values mapped to parameters are populated with data.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.

243 questions
1
vote
1 answer

ExecuteNonQuery from SQLHelper

I found this SQLHelper online that I would like to run a SQL query with. But the helper wants an list instead of an string. and I cannot seem to figure out how to make the executeNonQuery to work. type SqlHelper (connection) = let exec…
Dymond
  • 2,158
  • 7
  • 45
  • 80
1
vote
3 answers

Get RecordId from table

I am new to SQL, I have table with RecordId that is incremented automatically and is primary key. I would like to get RecordId of the row that was inserted into table. Thanks in advance for help. myCommand.CommandText = "INSERT INTO " + tableName +…
Pawel G
  • 47
  • 4
1
vote
3 answers

I am having an Insert into error with my query in vb.net

I am trying to insert data into an Access database table using an insert query, I get the error Syntax error in INSERT INTO statement. I have even tried the sql string without parameters and get the same error but if I paste the same query straight…
quell2727
  • 13
  • 2
1
vote
4 answers

Executenonquery return value

I want to perform a search on a table to see if record exists. I do not want to perform insert or update after. I have done this already but somehow I cannot get this to work. On my asp.net page I cannot seem to get any value returned. The error is…
mick
  • 139
  • 3
  • 16
1
vote
1 answer

SQL Server 2008: Executenonquery not returning number of rows affected

From C# I launch an update query using (a stored procedure): command.ExecuteNonQuery(...); Then in the stored procedure, I build a dynamic query and execute using sp_executesql: DECLARE @ParmDefinition NVARCHAR(500) DECLARE @pParam1…
Willy
  • 9,848
  • 22
  • 141
  • 284
1
vote
1 answer

MySQL row_count() rows affected

There is very little documentation on MySQL's row_count() function. Is this function specific to each stored procedure (i.e. will multiple instances of the same stored procedure executing at the same time return the correct result)? Is there any…
Greg
  • 11
  • 1
  • 2
1
vote
1 answer

SQL Error when adding primary key

When I attempt to add a new record and hence add a primary key, I get an error: System.Data.SqlClient.SqlException occurred HResult=0x80131904 Message=Violation of PRIMARY KEY constraint 'PK__Stock__BEAEB27A2652D17F'. Cannot insert duplicate…
Bleari
  • 175
  • 1
  • 1
  • 8
1
vote
1 answer

What will ExecuteNonQuery return when dropping a table?

Suppose we execute a DROP TABLE X through an ExecuteNonQuery and everything runs fine (without exception), what will it return?
Gabriel
  • 2,841
  • 4
  • 33
  • 43
1
vote
2 answers

ExecuteNonQuery() always returning -1

I'm creating a login application with C# and SQL Server. What my program does: it looks if the given username and password can be found in the database. If it can be found, ExecuteNonQuery() should return 1 (1 row found). If the combination doesn't…
Cihan Kurt
  • 343
  • 1
  • 5
  • 21
1
vote
3 answers

ExecuteNonQuery always returns -1

I have created a stored procedure for deleting record. In this stored procedure I am first checking for the usage of data which I am going to delete. If it is being used, then the stored procedure will return -2 otherwise it deletes the record. But…
Moin Khan
  • 37
  • 11
1
vote
1 answer

Database Locked even after disposing all commands

The database is locked error appears even after I have disposed all the commands. I'm trying to write to the database and it is failing on the INSERT command at the bottom. I had it working before but for some reason it has started to fail now. Sub…
Zac Evans
  • 51
  • 1
  • 8
1
vote
3 answers

SQL Statement for ExecuteNonQuery in C#

I am trying to insert a new row into a table in my SQL database through a webform. The problem is that I need to place the DateTime value in the Description of when the assignment of deliveryman was done. But because the value is a string and the…
unsolveBleu
  • 17
  • 1
  • 3
1
vote
1 answer

C# - ExecuteNonQuery isn't executing stored procedure

I am trying to run a stored procedure with parameters as shown below: Stored procedure: CREATE PROCEDURE [dbo].[spPurchase] @commodityName VARCHAR(10), @startdate DATE, @enddate DATE, @tonnes FLOAT, @lots INT, @value…
Johnathan
  • 879
  • 3
  • 12
  • 22
1
vote
2 answers

SqlException.Message duplicated when calling sqlserver stored proc

I have a stored procedure that gives a friendly enough error that I want to show to the users but when I call it from .net it comes out twice. When I call the proc from sql server management studio it only comes out once. Here is a cutdown version…
Adam Butler
  • 3,023
  • 5
  • 35
  • 40
1
vote
0 answers

Wufoo Form throwing up error on entry 'Could not execute nonquery'

Embedded a Wufoo form on my site using the downloaded HTML & stylesheets from the form on the Wufoo site. However after embedding I continually get the error 'Could not execute nonquery' on correct entry. It takes me to the Wufoo form on the Wufoo…
Archie
  • 97
  • 1
  • 2
  • 6