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

sqlcommand execute query not updating deleting and inserting

Hello i always use SQlcommand for non query but now something wrong i dont know what i have 3 buttons with operations update insert and delete but i created unique method for all 3 operations, the problem is it doesn't insert delete or…
0
votes
2 answers

Why ExecuteNonQuery() returning -1 without any exception and without inserting the entry in database?

I have following function: public Exception createTopic(Topic t) { query = "insert into [DisData].[dbo].[discussions]([title],[description],[usrid],[dateadded],[desid],[likes],[shares],[visit],[replyto],[sno])…
Aishwarya Shiva
  • 3,460
  • 15
  • 58
  • 107
0
votes
1 answer

My Connection already open but why the system said it closed?

ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. Why always the system returns that message? I have a sub: Private Sub Initialization() If myCEConnection.State = ConnectionState.Closed…
mrjimoy_05
  • 3,452
  • 9
  • 58
  • 95
-1
votes
2 answers

MySqlCommand.ExecuteNonQuery error and strange c#

I try to insert pathname to mysql database, but its working but its strange. What I found is the path isnt the path of my project directory its something strange. when i use my program the result is "D:musicFOREIGN!!New folderarat cakepHilary Duff -…
-1
votes
2 answers

SQL Joins are not working in Powershell Scripts. Throwing Error

I wrote a SQL script that provides result from the same table through the ID. I need to use this script in PowerShell to extract a result for a purpose. It works in SQL, but it doesn't works in Powershell. Tried using with or without Join…
-1
votes
1 answer

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

The code: private void btnSave_Click(object sender, EventArgs e) { using (con = new SqlConnection(connectionString)) { SqlCommand cmd; switch (action) …
Richard Johnson
  • 309
  • 4
  • 17
-1
votes
2 answers

datetime format changes upon oledbCommand.executeNonQuery

i have an sql insert query in my website,which inserts a few strings and ints, and a datetime in "dd/MM/yyyy HH:mm:ss", and until today it worked great. however, from today, for some odd reason, during the executeNonQuery method of the query, the…
Castleking1810
  • 77
  • 1
  • 11
-1
votes
1 answer

Connection not open error Visual Studio c# OleDB

I would like to put into a list the new ID-Machine (is not automatic), the name of the new machine and select the area (Bereich) where this type of machine belongs to. I try to change to string the ID-number (like in databease access) the ID to get…
-1
votes
1 answer

Login Comparing hash value in a database

I am attempting to make a simple sign on portion of an app I am creating. To confirm sign in, I am just attempting to make sure that the hash value of the password entered, matches that which is stored in my local database: App_Users ) '…
Jponder23
  • 27
  • 6
-1
votes
3 answers

C# DBNull.Value Inserting 0

I am trying to insert data into a SQL table. The data types I am having issues with are nullable floats. When the NULL values are inserted they change to 0. How can I keep them NULL. private void InsertStatisticsData(DataTable dt) { //check…
Mwspencer
  • 1,142
  • 3
  • 18
  • 35
-1
votes
2 answers

SQLException Occured: Incorrect syntax near ' '

I get SqlException: incorrect syntax near nvarchar Incorrect syntax near 'ID' in my code. Please can somebody help me solve it? My code is using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using…
-1
votes
1 answer

INSERT Query errors in Vb.net (Ms-AccessDb) / exception : 'incorrect'

Anyone can help me with this please ? The app you see rn is nothing like the app im working on , i made it way simple. ** because of the versions ?? I'm using VB.net2017 / Ms-AccessDb 2010** this code below is a simple version that i made , of my…
iifast2
  • 303
  • 1
  • 3
  • 9
-1
votes
1 answer

syntax error non query c#

for school I need to make a web application with c# and mysql. In the application there is a registration page but when I click on the button to finish I get a syntax error that says that the execute.nonquery is wrong. Can somebody help me ? This…
-1
votes
1 answer

error Incorrect syntax near in c#

This statement gives the following error: An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: Incorrect syntax near ','. Note: My table has 22 fields thanks for your…
-1
votes
1 answer

Error "'System.Data.SqlClient.SqlException' happened when trying to debug application

I'm creating an application where I store my inputs (name, age, phone) from the textbox and when I click Submit, it should store whatever I input onto the textbox into the database but I keep getting this error. An exception of type…
amiiBRO
  • 1
  • 2