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

SQL ExecuteNonQuery: Connection property has not been initialized

I'm trying to figure out how to save to db an image. I wrote the following code, but I keep getting this error on line 51, which is cmd.ExecuteNonQuery;. I can't figure out why. The connection ("conn") is already opened before it, but still shows…
Ezekiel
  • 333
  • 4
  • 9
  • 27
0
votes
3 answers

C# MySqlCommand Insert shows fatal error command

I have a table (Horario) with the following types: id (int, auto increment) codMedico (int) dia (Date) horarioInicio (Time) horarioFim (Time) status_id (int) I can't see any problem on the code below, but it just shows me "fatal error" on…
0
votes
0 answers

Resulting SQL from a prepared statement

I'm using Prepared Statement in Visual Studio 2012 c#. I use using(SqlTransaction transaction = conn.BeginTransaction()) and preparedStmt.ExecuteNonQuery(). Is it possible, after executing ExecuteNonQuery() or preferably before it, retrieve the…
Hikari
  • 3,797
  • 12
  • 47
  • 77
0
votes
0 answers

ALTER TABLE doesn't work

I'm trying to change my column datatype in the table item. Now it has just 0(it's int now). What will happen when I run it? I tried to use int num = cmd.ExecuteNonQuery() but didn't work, it came an error. With this code I don't see changes. I found…
0
votes
2 answers

ADO.NET and ExecuteNonQuery: how to use DDL

I execute SQL scripts to change the database schema. It looks something like this: using (var command = connection.CreateCommand()) { command.CommandText = script; command.ExecuteNonQuery(); } Additionally, the commands are executed within…
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
0
votes
0 answers

visual studio 2010 showing Syntax error near ')' at y.ExecuteNonQuery code

The following code snippet is for storing values in a table from grid view . And it is showing Unhandled SQLException at the line y.ExecuteNonQuery the error is Syntax error near ')' however i cannot determine what's wrong with the code. Help me…
0
votes
2 answers

MySQL query error in c#

When i run the query from visual studio c# insert into nts1.empty_routes_mip select @rownum := @rownum + 1, station_from_id, station_to_id, nko_empty_run, cost, nko_min, nko_max, nko_ratio_1, nko_ratio_2 from nts1.empty_routes, (SELECT @rownum :=…
0
votes
1 answer

sql query result from executenonquery to text file vb.net

Please see the following Code: Imports System.Data Imports System.Data.SqlClient Imports System.IO Public Class frm_main Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim sqlFile As String =…
AmitGogna
  • 5
  • 2
0
votes
2 answers

Why is this SQLite Insert failing?

I've got this code to insert 1..N records in a SQLite database in a Windows CE / Compact Framework app: void IPlatypusDBUtils.SaveSiteMappingData(IEnumerable siteMappings) { ExceptionLoggingService.Instance.WriteLog("Reached…
0
votes
1 answer

Sending output parameters and getting multiple datasets from Stored procedure C#

My stored procedure :- DECLARE @return_value int, @Sum int, @Total float EXEC @return_value = [dbo].[mysamplesp] @sd = '2014-09-23 00:00:00.000', @ed = '2014-09-30 00:00:00.000', @ID = '40494', @sp…
0
votes
1 answer

DbCommand.ExecuteNonQuery error handling

When I use the DbCommand.ExecuteNonQuery() in .net, it will return a scalar. Is that the only information I will get from this command? Or is there also an exception, if for example the command is wrong, or there is a timeout or something else?
DanielG
  • 1,217
  • 1
  • 16
  • 37
0
votes
3 answers

Works perfectly except changes are not saved to the SQL database

Changes are not saved to the SQL database Why would I want to use '@' in the sql statement instead of the way that I have the statement? Code: private void button_Save_Customer_Click(object sender, EventArgs e) { sqlString =…
Dave Hampel
  • 160
  • 3
  • 13
0
votes
1 answer

ExecuteNonQuery - Data Type Mismatch in Criteria Expression when adding data (VB.Net and Excel 2010)

Good day to everybody. I wrote some code in vb.net to use a form to add a row into an Excel file (xls). Two textboxes are in the form. The two columns in the excel file are formatted as text. If I input any number into the textboxes everything works…
LukeLuke
  • 71
  • 1
  • 8
0
votes
1 answer

Syntax Error in INSERT INTO Statement (Insert Records)

can someone help me what is wrong with my code? It always says "Syntax error in INSERT INTO statement. " try { OleDbConnection Con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\MotoFix.mdb;"); …
Akemi Chou
  • 64
  • 1
  • 3
  • 10
0
votes
1 answer

INSERT query not working vb.net sql

I am working on a project! M using vb 2012 with .mdf as database! Problem is M unable to save record to database using the sql insert statement! PFB "app.config" | "insert code (save button click event)", and help me out! Its small mistake but m…
AmIt PagarIa
  • 35
  • 1
  • 11