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
2 answers

Using ExecuteNonQuery to run a Stored Procedure isn't creating my table, but the table is created when executing the sp in SSMS

Some notes: ExecuteNonQuery returns -1 ExecuteNonQuery will drop the table (@droptable), but it will not create the new table (@code) the length of the @code query is 10265 characters The stored procedure runs perfectly fine in SSMS and returns…
1
vote
2 answers

How to Insert Data to the Database? - User Defined Classes

I'm Experimenting with databases and I'm finding different methods to optimize my codes. Here I'm using a different class to stop re writing the same codes such as for add, Delete and update we use the same ExecuteNonQuery() method. So far Update…
Ashane Alvis
  • 770
  • 2
  • 18
  • 42
1
vote
1 answer

Error in OleDbTransaction

I'm doing a transaction with OleDb. I don't show how did I calculate the variables like finalQuantity and finalMoneyBuyer because it's not important. My code is this: using(OleDbConnection con = DAL.GetConnection()) { …
Pichi Wuana
  • 732
  • 2
  • 9
  • 35
1
vote
1 answer

sql ExecuteNonQuery doesn't update the database in C#

i'm making a small C# program that connects to MS SQL 2008 database. i have the following function, while i use a simmilar one to INSERT new data to database, when i want to update it, there are no changes in the database. Am i missing…
Iakovl
  • 1,013
  • 2
  • 13
  • 20
1
vote
1 answer

Entering data to SQL Server results in strange error

I'm having a strange issue with entering data into a SQL Server 2008 database, the error tells me that System.Data.SqlClient.SqlException was unhandled HResult=-2146232060 Message=The variable name '@comments' has already been declared. …
Iakovl
  • 1,013
  • 2
  • 13
  • 20
1
vote
2 answers

Error in server 'executenonquery requires an open and available connection'

I got this error on server not in local and when facing this error, then i re-upload that related class file. after doing this problem solved but not permanently. Error: executenonquery requires an open and available connection. The connection's…
Boktiar
  • 33
  • 2
  • 6
1
vote
2 answers

ExecuteNonQuery() throws "Incorrect syntax near the keyword 'User'"

I started learning C# last week and I'm now having trouble with an INSERT sql statement. I used the following code, then I tell you what happens. private void AddNewUserToDataBase(User user) { string commandText = "INSERT INTO User…
bengous
  • 205
  • 2
  • 4
  • 13
1
vote
2 answers

Trying to Insert Text to Access Database with ExecuteNonQueryin VB

I'm working on this feature were i save text from a textbox on my form to a access database file. With the click on my "store" button I want to save the text in the corresponding textbox fields to the fields in my access database for searching and…
Playergoodi
  • 71
  • 4
  • 12
1
vote
1 answer

ExecuteScalar Error when Creating Custom ID

im currently facing problem with executeScalar when i create custom ID. the error is InvalidOperationException was unhandled by user code. Message=Connection must be valid and open. Below is my code : Dim str As String = "select…
kolapopo
  • 108
  • 1
  • 4
  • 14
1
vote
1 answer

ExecuteNonQuery update does not store change

I am trying to update some fields in the database, using ExecuteNonQuery(). When trying to update, i receive no error or warning, and it returns me one affected row count. The thing is, that i can only for the current request, see the change. If i…
Jonas m
  • 2,646
  • 3
  • 22
  • 43
1
vote
2 answers

SQLCommand with Parameter no longer updates my table

I am modifying a previous developers code and found that he was not using parameters in his update statements. I went to modify it with parameters to make it safer against injection and now it won't update at all. It did update with the old code. …
John Wesley Gordon
  • 910
  • 2
  • 17
  • 39
1
vote
2 answers

ODP.NET array bind return/OUT param performance

Some old code that I have uses OracleDataAdaper.Update(DataSet). If I call a test stored proc (that only has input parameters), it takes about 24 seconds for 20,000 rows to be inserted. I needed to improve on that, so I switched to using array…
IMK
  • 152
  • 1
  • 1
  • 7
1
vote
1 answer

ExecuteNonQuery() for Insert

Can you please tell me what's wrong with this code? Do I need to use DataAdapter to insert into a table? I know the connectionString is ok, because I tested it on the Server Explorer. Dim mydao As New Connection Dim connectionString As…
phalanx
  • 497
  • 5
  • 17
  • 33
1
vote
1 answer

No data available after an Insert operation VB.NET - Windows Forms and Web Service

VB.NET and ASMX Web Service. I am still having the same trouble of getting no data after an insert operation. Here is my insert code: Try 'create a MySqlCommand to represent the query If sqlConn.State = ConnectionState.Closed Then …
Luckie
  • 21
  • 7
1
vote
4 answers

I am getting an error when I try to update records in my access database

I have a small program that connects to an access database, and what I am trying to do is update(edit) a selected record via an edit form. When I execute my code, I get this error: System.Data.OleDb.OleDbException was unhandled Message=Syntax…
Carson
  • 1,169
  • 13
  • 36