ExecuteNonQuery
public int ExecuteNonQuery(string query)
Executes a command - without parameters - that doesn't retrieve any data from the database (e.g. INSERT
, UPDATE
, DELETE
...), and returns the numbers of rows affected.
Parameters :
query - a string that represent the sql select query without parameters.
Return :
The numbers of rows affected by the query.
Throw :
InvalidOperationException, if the connection isn't opened.
public int ExecuteNonQuery(string query, params string[] sqlParameters)
Executes a command - with parameters - that doesn't retrieve any data from the database (e.g. INSERT
, UPDATE
, DELETE
...), and returns the numbers of rows affected.
Parameters :
query - a string that represent the sql_select_query with parameters. sqlParameters - One to many pairs of strings, parameter's name first followed by the value. (E.g.: "param1", "value1", "param2", "value2"...).
Notice : Be sure to always write pairs of strings, or it won't work.
E.g:
sql.ExecuteNonQuery("delete from table where categoryId = @Id AND productType = @type", "id", "12", "type", "2");
Return :
The numbers of rows affected by the query.
Throw :
InvalidOperationException, if the connection isn't opened.
ArgumentException, if the number of parameters isn't even
Last updated
Was this helpful?