Sqlcommand. executenonqueryMethod
Execute the transact-SQL statement on the connection and return the affected number of rows.
-Syntax:
Public override int executenonquery ()
-- Return Value
Type: system...:. int32
Number of affected rows.
-Executenonquery can be used to perform directory operations (such as querying the database structure or creating database objects such as tables), or by executing update, insert, or delete st
I. Principles of SqlDataAdapter and DateSet: DateSet is the memory resident representation of data. It provides a consistent relational programming model independent of the data source; to some extent, DateSet is an invisible database. But what really deals with the data source is SqlDataAdapter, including filling in the data source and updating the data source from the dataset. SqlDataAdapter uses the Fill () method to populate the retrieved data with DateSet. Process: IE -- GridView -- DataSet
(This post is posted on the old blog of the version engineer on)Sometimes, according to the project requirements, we may need to obtain multiple sets of datatables from the database, and thenLineCompile the code and present it on the ASP. NET 2.0 page in the desired format, instead of directly binding it to the gridview control. You can refer to the following practices.To join data from multiple tables in the database, multiple records (quantity is not fixed) and multiple columns are retrieved a
Tags: lda scale scalar code log same get query calMethods of the SqlCommand class----"" 1.ExecuteNonQuery ();It has a return value of type int. Many are used to perform an increase, delete, modify data, and return the number of rows affected. When the select operation, returns-1.ExecuteNonQuery () method The primary user updates the data, usually it uses the Update,insert,delete statement to manipulate the database. Its method returns the value meanin
Tags: style blog io color os ar using SP strongSQLcommand represents a T-SQL statement or stored procedure to be executed against the SQL database. to perform a large number of operations or work with the database structure. This is often used when accessing a database. Let's see how it's done!First, the attribute
CommandText
Gets or sets the data source to be executed on the Transact - SQL statement or stored procedure.
CommandType
Gets or sets a value that
The following example creates a SqlCommand and runs it using ExecuteScalar. Two strings are passed to this example. One String indicates the new value to be inserted into the table, and the other string is used to connect to the data source. If a new row has been inserted, this function returns the value of the new "Identity" column. If it fails, 0 is returned.
01
static
public
int
AddProductCategory(
string
newName,
string
connString)
02
{
1. Use the New Keyword to directly create an instance of the object and set the appropriate attributes:
String strconn, strsql;
Strconn = @ "Data Source =. \ sqlexpress;" + "Initial catalog = northwind; trusted_connection = yes ";
Strsql = "select customerid, companyName from customers ";
Sqlconnection Cn = new sqlconnection (strconn );
CN. open ();
Sqlcommand cmd;
Cmd = new sqlcommand ();
Cmd. Co
Recently, when I was doing a batch of data processing performance tuning, I found that the typical audit login and audit logout are not found in sqlprofiler, if the commandtext comment value of the command sentence is not logged out before the update or add operation of the latest row data, if the threshold value is later, logout will be generated. I do not know why. The performance deviation may reach 15%-20%.
If the explain method is as follows:Create a consumer connected to conn;
Label:1.SqlCommand. ExecuteNonQuery Method Executes Transact-SQL statements on the connection and returns the number of rows affected. Syntax: public override int ExecuteNonQuery () return value: Type: System.Int32 Number of rows affected Attention: ① for UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. If there is a trigger on the table that is performing the insert or update operation, the retu
Sqlcommand. executescalar Method
Returns the first column of the First row in the returned result set. Ignore other columns or rows.
Namespace:System. Data. sqlclientAssembly:System. Data (in system. Data. dllMedium)Syntax
C #
public override Object ExecuteScalar ()
Return Value
The first column or empty reference of the first row in the result set (if the result set is empty ).Exception
Exception type
Condition
Sqlexception
1. sqldatareader: for online applications, conn. open () is required. Close it after use.
Sqlconnection conn = new sqlconnection (connstr );// Conn. open ();Sqlcommand cmd = new sqlcommand ("select top 10 * From Tuser", Conn );Sqldatareader reader = cmd. executereader (commandbehavior. closeconnection );While (reader. Read ()){Console. writeline (reader. getvalue (2 ));}This sectionCodeError: executereade
episode (a) Add all properties of the class as SqlCommand parametersWhen executing a stored procedure using SqlCommand, if the stored procedure requires parameters, each parameter must be entered, although the AddWithValue method can be used, but the parameters are still a bit cumbersome.When you need to use all the properties of a class as arguments, you can get all the properties and values of the class t
Why does the sqlcommand. executenonquery () method return-1?
I don't know if you have encountered the case of returning-1 when using the executenonquery method. The number of affected rows returned by the executenonquery method during addition, deletion, and modification. Then how does one return-1? After checking some information, I finally learned why-1 was returned.
When adding, deleting, and modifying data, the database can calculate the number
Sqlcommand. executenonquery MethodExecute a Transact-SQL statement on the connection and return the affected number of rows, which is an int data type.Namespace:System. Data. sqlclientAssembly:System. Data (in system. Data. dllMedium)SyntaxC #public override int ExecuteNonQuery ()C ++public:virtual int ExecuteNonQuery () overrideJ #public int ExecuteNonQuery ()JScriptpublic override function ExecuteNonQuery () : intReturn ValueNumber of affected rows.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.