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
votes
1 answer

Execute multiple simultaneous SqlCommand.ExecuteNonQuery() and be notified when they finish

I have a set of SQL commands that don't return a query, only the amount of affected records. They run in different servers. They can run simultaneously, I don't need to wait one finish to start another. I'm developing a C# app, I'd like to execute…
Hikari
  • 3,797
  • 12
  • 47
  • 77
-1
votes
2 answers

ExecuteNonQuery CommandText property has not been initialized

When I click on this button, I face with this error: executenonquery commandtext property has not been initialized private void button_FirstStep_Click(object sender, EventArgs e) { SqlConnection Conn = new SqlConnection(Yahya.strcon); …
Yahya Zahedi
  • 21
  • 1
  • 1
  • 1
-1
votes
1 answer

C#/SQL Error "Object not set to an instance of an object"

This may not actually be a code issue, but here goes... My C# program reads a CSV file and builds an SQL Insert statement to insert all rows of the file into a table, so the Insert statement becomes: Insert GHP_For_CMS (GroupId, EmployeeID, etc...)…
-1
votes
1 answer

C# An exception of type 'System.Data.SqlClient.SqlException on ExecuteNonQuery

Here is the code: protected void addBtstu1_Click(object sender, EventArgs e) { using (SqlConnection stu = new SqlConnection("Data Source=.\\SQLEXPRESS; Database=DB; User Id=sa; password=123")) { stu.Open(); …
-1
votes
2 answers

error on ExecuteNoQuery()

i'am trying to update a row in a table using : command.ExecuteNoQuery() it's not giving me an error but it's not updating the row This is my code : Dim req As String = "Update Table Set Id= 5" Dim cmd As New OleDb.OleDbCommand(req,…
Wassim AZIRAR
  • 10,823
  • 38
  • 121
  • 174
-1
votes
1 answer

What is with this error? ExecuteNonQuery: CommandText property has not been initialized

Please help guys. It works perfectly when updating without the current password and the new password BUT if i will include to update the password, it throws an error. Here's my code: protected void UpdateBtn_Click(object sender, EventArgs e) …
raurau
  • 11
  • 1
-1
votes
1 answer

How to execute a stored procedure containing INSERT and SELECT both statements

In my stored procedure, first i do INSERT query and then have SELECT statement as follow: INSERT () SELECT * FROM preferences WHERE ID=@ID In ADO.NET, i have used - datareader to execute this procedure. But, it does not return the…
user3711357
  • 1,425
  • 7
  • 32
  • 54
-1
votes
2 answers

Commandobject.executenonquery() and Commandobject.executereader() give different results for count(*)

I'm trying to create a login page and when i give executereader it works and when i give executenonquery it returns a -1 value instead of 1. This return -1 on cmd.executenonquery() SqlCommand cmd = new SqlCommand("select Count(*) from userDb where…
Sainath
  • 979
  • 2
  • 13
  • 22
-1
votes
2 answers

ExecuteNonQuery with DeleteCommand?

I need use ExecuteNonQuery at those syntax's below? And they are correct? Objective use the da.DeleteCommand; which syntax's I gain performance? MySqlCommand cmd = new MySqlCommand("DELETE FROM users_login WHERE UserID = @UserID;",…
Bruno Casali
  • 1,339
  • 2
  • 17
  • 32
-1
votes
3 answers

How to solve ExecuteNonQuery: Connection property has not been initialized

I am a newbie C# programmer. I try to make game with C#. At my register page it got some error. It said that ExecuteNonQuery: Connection property has not been initializedat this line "int result = command.ExecuteNonQuery();".Here is my C# code.…
user2187208
  • 1
  • 1
  • 2
-2
votes
2 answers

Error ExecuteNonQuery: Connection property has not been initialized C# (Access)

I have some code like this: var queryIns = "..."; try { var rowInsert = u.insert(queryIns); } catch (Exception) { var msg = "Error"; MessageBox.Show(msg,...); } and my command is: public int Command(string queryCommand) { using var…
galidan
  • 17
  • 3
-2
votes
1 answer

How to get the number of rows affected, if it hits sql exception while running the sql script in c#

I need to get the number of rows affected if ExecuteNonQuery() hits the SqlException. I'm able to see the Number of affected rows while debugging in c#, but unable to get that, like- cmd.InternalRecordsAffected cmd._rowsAffected I have already…
Rutuja
  • 7
  • 3
-2
votes
1 answer

ExecuteNonQuery showing error

I've updated my code and have parameters set for the statements. Everything works fine the way it should except for the update statement, no error is given and it completes the else statement but it doesn't update the database. Is the update code…
abr
  • 27
  • 6
-2
votes
1 answer

C# Command.ExecuteNonQuery(); Error Incorrect syntax near 'VALUE'

I've tried a ton of different things with this, I keep getting the same error on my cmd.ExecuteNonQuery(); It throws me this. An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional…
Morten Paaske
  • 35
  • 1
  • 1
  • 6
-3
votes
1 answer

How can i update data in c#

I'm working in Visual Studio 2019 In c I have problem with updating data to database I use local Visual Studio SQL database private void button1_Click(object sender, EventArgs e) { String source = @"Data…
Szabolcs
  • 11
  • 3
1 2 3
16
17