انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

SQLCommand Class in the .NET in C# Overview

الكلية كلية تكنولوجيا المعلومات     القسم قسم شبكات المعلومات     المرحلة 4
أستاذ المادة حۡــسۜــنۨ ا̍ڷــڔهــٻۧــمۘــې       20/04/2013 14:44:16
Represents a Transact-SQL statement or stored procedure to execute against a SQL Server database. This class cannot be inherited.


SqlCommand.ExecuteScalar Method
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored. Use the ExecuteScalar method to retrieve a single value (for example, an aggregate value) from a database. This requires less code than using the ExecuteReader method, A typical ExecuteScalar query can be formatted as in the following C# example:


SqlCommand.ExecuteReader Method
Sends the CommandText to the Connection and builds a SqlDataReader. When the CommandType property is set to StoredProcedure, the CommandText property should be set to the name of the stored procedure. The command executes this stored procedure when you call ExecuteReader. If a transaction is deadlocked, an exception may not be thrown until Read is called.



SqlCommand.ExecuteXmlReader Method
Sends the CommandText to the Connection and builds an XmlReader object. The CommandText property ordinarily specifies a Transact-SQL statement with a valid FOR XML clause. However, CommandText can also specify a statement that returns ntext or nvarchar data that contains valid XML, or the contents of a column defined with the xml data type. A typical ExecuteXmlReader query can be formatted ,This method can also be used to retrieve a single-row, single-column result set that contains XML data. In this case, if more than one row is returned, the ExecuteXml Reader method attaches the XmlReader to the value on the first row, and discards the rest of the result set.The multiple active result set (MARS) feature allows for multiple actions using the same connection.



SqlCommand.ExecuteNonQuery Method
Executes a Transact-SQL statement against the connection and returns the number of rows affected. 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 returns no 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. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.


المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .