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
3
votes
3 answers

ExecuteNonQuery not working in C#

I am building a database using Visual Studio 2008 c# and when I'm a trying to insert a new record into my database it appears that ExecuteNonQuery has not initialized. I copy my code, hope anyone can help me in this because I am new. private void…
Ivan Fernandez
  • 31
  • 1
  • 1
  • 2
3
votes
1 answer

SQL - Syntax error from a string that is not in the query

In my application, I get a weird error at multiple locations. Basically, I call a stored procedure in the database using an SqlManager and the executeNonQuery() method but I get an exception saying: Incorrect syntax near '44444' in Visual…
Hugo Trudel
  • 225
  • 3
  • 12
3
votes
6 answers

ExecuteNonQuery() not saving any record

I'm working a WinForms based C# tool which has an attached MDF file based database. I'm trying to use the SqlCommand.ExecuteNonQuery() method to save a record to this attached MDF database, but the record is not saved. No error or exception occurs;…
Ahmad
  • 12,886
  • 30
  • 93
  • 146
3
votes
1 answer

ExecuteNonQuery: Connection property has not been initialized

I've seen this question asked here before, but never when Enterprise Library is used. I've used code like the following before and it works fine. What's the problem this time? I get the error on the last line: Database db = new…
birdus
  • 7,062
  • 17
  • 59
  • 89
2
votes
1 answer

ExecuteNonQuery always returns -1 even when the SQL statement is correct

I'm using the following function to calculate sum qty value of given item code(VB.NET, SQL Server, SQL). I do not get any errors but the returned value by the function is always -1. The data is available in the table(Screenshot attached). I think,…
2
votes
3 answers

Return ID of newly inserted row on a PostgreSQL database using C# and Npgsql?

I'm building a WinForms project in C# using a PostgreSQL database and the Npgsql framework. For inserting a record, I need to return the ID of the new record. This SO question says to add SELECT SCOPE_IDENTITY() to the query string passed to cmd. So…
marky
  • 4,878
  • 17
  • 59
  • 103
2
votes
1 answer

6502 from ODP.NET on a function returning string

I have a SQL function defined as such: create or replace function func_cmap_unit_test (what varchar2) return varchar2 as begin return 'hello ' || what || '!'; end func_cmap_unit_test; I tested in SQL Developer and it works fine: select…
Johnny Wu
  • 1,297
  • 15
  • 31
2
votes
4 answers

Error while using ExecuteNonQuery c#

I have a problem while using ExecuteNonQuery. This is my code : var connString = @"Data Source=serwer01;Initial Catalog=PolsatCyfrowy;Integrated Security=True"; FileInfo file = new FileInfo("C:\\Users\\azbudniewek\\source\\repos\\UM2 V2\\UM2…
Adam Zbudniewek
  • 107
  • 2
  • 12
2
votes
1 answer

Handle leak in C# ADO.Net Application

Here is a short code snippet to execute a query using ADO.Net using(SqlConnection objSqlConnection = new SqlConnection(sConnectionString)) { objSqlConnection.Open(); using (SqlCommand objSqlCommand = new SqlCommand(sSQLQuery,…
2
votes
1 answer

ExecuteNonQuery is working but , changes are not saving

here is the code im working on ; public partial class Form2 : Form { SqlConnection sc = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"); SqlDataAdapter sda; …
2
votes
2 answers

How to pass variable into SqlCommand statement and insert into database table

I'm writing a small program in C# that uses SQL to store values into a database at runtime based on input by the user. The only problem is I can't figure out the correct Sql syntax to pass variables into my database. private void…
Rupert
  • 75
  • 1
  • 3
  • 7
2
votes
2 answers

c# MySqlCommand.ExecuteNonQuery() return -1

I'm trying to execute a SQL request in C# to know if a user is already registered on my data base. To do that, I'm using the following source code : public bool pseudoDispo(string pseudo) { // Ouverture de la connexion SQL …
Y.Paulet
  • 47
  • 1
  • 8
2
votes
3 answers

ExecuteNonQuery() breaks the loop and doesn't insert data in SQL database

Here's the code which tries to enter the data stored in the arrays. The arrays contain data as well as there are empty cells which need not be added into the database. The issue is the code is not throwing any exception or error but it isn't…
2
votes
0 answers

It always go to OleDbException

using(OleDbConnection con = DAL.GetConnection()) { OleDbTransaction transaction = null; try { con.Open(); transaction = con.BeginTransaction(); if…
2
votes
1 answer

Jet Database (ms access) ExecuteNonQuery - Can I make it faster?

I have this generic routine that I wrote that takes a list of sql strings and executes them against the database. Is there any way I can make this work faster? Typically it'll see maybe 200 inserts or deletes or updates at a time. Sometimes there is…
Bluebill
  • 147
  • 2
  • 11
1 2
3
16 17