Gracias por visitar este Blog ...Donde encontraran material interesante sobre temas relacionados al ámbito educativo y tecnológico tales como: Programas, Clases de Ing. de Sistemas y Telemática, diseño ,elaboración y solución de problemas usando los diferentes lenguajes de programación(Java,Visual Studio o Basic,otros) . Propuesto para personas que necesitan superarse cada día y formar una buena ética profesional.!!!...
domingo, 26 de noviembre de 2017
jueves, 16 de noviembre de 2017
domingo, 12 de noviembre de 2017
I.
Tema: Objeto SqlCommand
1. Contenido
v Definición
Un SqlCommand se utiliza cuando necesitas
ejecutar un tipo de sentencia Sql a la base de datos (los tipos pueden ser:
Delete, Update, Insert o Select). Cuando se crea una instancia de SqlCommand,
las propiedades de lectura y escritura se establecen en sus valores iniciales.
Para obtener una lista de esos valores, vea el constructor SqlCommand.
Obtiene o establece un valor que indica cómo se
interpreta la
Propiedad CommandText. Representa un
procedimiento almacenado o una instrucción de Transact-SQL que se ejecuta en
una base de datos de SQL Server.
v Propiedades
ColumnEncryptionSetting
Obtiene o establece la configuración del cifrado de columnas para este
comando.
Ejemplo:
<BrowsableAttribute(False)>
CommandType
CommandType.TextEnd Sub
CommandTimeout
Obtiene o establece el tiempo de espera antes de terminar el intento de
ejecutar un comando y generar un error.
CommandText
Obtiene o establece la instrucción de Transact-SQL, el
nombre de tabla o el procedimiento almacenado que se ejecutan en el origen de
datos.
Connection
Obtiene o establece la interfaz SqlConnection que usa esta
instancia de SqlCommand.
Ejemplo:
Public Property
Connection As SqlConnection
Container
Obtiene IContainer que contiene Component.(Heredado
de Component).
Ejemplo:
<BrowsableAttribute(False)>Public
ReadOnly Property
Container As IContainer
DesignTimeVisible
Obtiene o establece un valor que indica si el objeto de comando
debe estar visible en un control del Diseñador de Windows
Forms.(Invalida DbCommand.DesignTimeVisible).
Ejemplo:
<BrowsableAttribute(False)>Public Overrides Property
DesignTimeVisible As Boolean Notification Obtiene o establece
un valor que especifica el objetoSqlNotificationRequest
v Métodos
BeginExecuteNonQuery()
Inicia la ejecución asincrónica de la instrucción de
Transact-SQL o del procedimiento almacenado que describe SqlCommand
BeginExecuteNonQuery(AsyncCallback,
Object)
Inicia la ejecución asincrónica de la instrucción de
Transact-SQL o del procedimiento almacenado que describe SqlCommand, dados un procedimiento
de devolución de llamada e información de estado
BeginExecuteReader()
Inicia la ejecución asincrónica de la
instrucción de Transact-SQL o del procedimiento almacenado que describe
SqlCommand y recupera uno o varios conjuntos de resultados del servidor
BeginExecuteReader(AsyncCallback, Object)
Inicia la ejecución asincrónica de la
instrucción de Transact-SQL o del procedimiento almacenado que describe
SqlCommand y recupera uno o varios conjuntos de resultados del servidor, dados
un procedimiento de devolución de llamada e información de estado
SqlParameterCollection
Ejemplo:
Public ReadOnly Property Parameters As SqlParameterCollection
Site Obtiene o establece la ISite de la Component.(Heredadode Component)
SqlCommand
Ejemplo:
<BrowsableAttribute(False)>Public Property Transaction
As SqlTransaction UpdatedRowSourceObtiene o establece la manera en que se
aplican los resultados del comando a DataRow cuando lo utiliza método Update
deDbDataAdapter.(Invalida DbCommand.
UpdatedRowSource).
Ejemplo:
Public Overrides
Property UpdatedRowSource As UpdateRowSource
BeginExecuteReader:
Inicia la ejecución asincrónica de la instrucción de Transact-SQL
o del procedimiento almacenado que describe SqlCommand, utilizando uno de los
valores de CommandBehavior y recuperando uno o varios conjuntos de resultados
del servidor, a partir del procedimiento de devolución de llamada e información
de estado dados.
EJEMPLO
<HostProtectionAttribute(SecurityAction.LinkDemand,
ExternalThreading :=
True)>Public Function
BeginExecuteReader (
callback As AsyncCallback,
stateObject As Object,
behavior As
CommandBehavior) As IAsyncResult
BeginExecuteReader(CommandBehavior)
Inicia la ejecución asincrónica de la instrucción de
Transact-SQL o del procedimiento almacenado que describe SqlCommand utilizando
uno de los valores de CommandBehavior
EJEMPLO:
<HostProtectionAttribute Public
Function
BeginExecuteReader ( behavior As CommandBehavior) As
IAsyncResultBeginExecuteXmlReader()
v Ejemplos
private static void ReadOrderData(string connectionString)
{
string queryString =
"SELECT
OrderID, CustomerID FROM dbo.Orders;";
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlCommand command = new SqlCommand(
queryString,
connection);
connection.Open();
SqlDataReader reader =
command.ExecuteReader();
try
{
while (reader.Read())
{
Console.WriteLine(String.Format("{0},
{1}",
reader[0],
reader[1]));
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}
}
El ejemplo siguiente muestra cómo crear y ejecutar
diferentes tipos de objetos de SqlCommand.
En primer lugar debe crear la base de datos de
ejemplo, mediante la ejecución de la secuencia de comandos siguiente:
USE [master]
GO
CREATE DATABASE [MySchool]
GO
USE [MySchool]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[CourseExtInfo] @CourseId int
as
select c.CourseID,c.Title,c.Credits,d.Name as DepartmentName
from Course as c left outer join Department as d on
c.DepartmentID=d.DepartmentID
where c.CourseID=@CourseId
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[DepartmentInfo] @DepartmentId int,@CourseCount
int output
as
select @CourseCount=Count(c.CourseID)
from course as c
where c.DepartmentID=@DepartmentId
select d.DepartmentID,d.Name,d.Budget,d.StartDate,d.Administrator
from Department as d
where d.DepartmentID=@DepartmentId
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE [dbo].[GetDepartmentsOfSpecifiedYear]
@Year int,@BudgetSum money output
AS
BEGIN
SELECT
@BudgetSum=SUM([Budget])
FROM
[MySchool].[dbo].[Department]
Where YEAR([StartDate])=@Year
SELECT [DepartmentID]
,[Name]
,[Budget]
,[StartDate]
,[Administrator]
FROM
[MySchool].[dbo].[Department]
Where YEAR([StartDate])=@Year
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Course](
[CourseID] [nvarchar](10) NOT NULL,
[Year] [smallint] NOT NULL,
[Title] [nvarchar](100) NOT NULL,
[Credits] [int] NOT NULL,
[DepartmentID] [int] NOT NULL,
CONSTRAINT [PK_Course] PRIMARY
KEY CLUSTERED ([CourseID] ASC,
[Year] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Department](
[DepartmentID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[Budget] [money] NOT NULL,
[StartDate] [datetime] NOT NULL,
[Administrator] [int] NULL,
CONSTRAINT [PK_Department]
PRIMARY KEY CLUSTERED
(
[DepartmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Person](
[PersonID] [int] IDENTITY(1,1) NOT NULL,
[LastName] [nvarchar](50) NOT NULL,
[FirstName] [nvarchar](50) NOT NULL,
[HireDate] [datetime] NULL,
[EnrollmentDate] [datetime] NULL,
CONSTRAINT [PK_School.Student]
PRIMARY KEY CLUSTERED
(
[PersonID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[StudentGrade](
[EnrollmentID] [int] IDENTITY(1,1) NOT NULL,
[CourseID] [nvarchar](10) NOT NULL,
[StudentID] [int] NOT NULL,
[Grade] [decimal](3, 2) NOT NULL,
CONSTRAINT [PK_StudentGrade]
PRIMARY KEY CLUSTERED
(
[EnrollmentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[EnglishCourse]
as
select c.CourseID,c.Title,c.Credits,c.DepartmentID
from Course as c join Department as d on c.DepartmentID=d.DepartmentID
where d.Name=N'English'
GO
INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits],
[DepartmentID]) VALUES (N'C1045', 2012, N'Calculus', 4, 7)
INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits],
[DepartmentID]) VALUES (N'C1061', 2012, N'Physics', 4, 1)
INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits],
[DepartmentID]) VALUES (N'C2021', 2012, N'Composition', 3, 2)
INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits],
[DepartmentID]) VALUES (N'C2042', 2012, N'Literature', 4, 2)
SET IDENTITY_INSERT [dbo].[Department] ON
INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget],
[StartDate], [Administrator]) VALUES (1, N'Engineering', 350000.0000, CAST(0x0000999C00000000
AS DateTime), 2)
INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget],
[StartDate], [Administrator]) VALUES (2, N'English', 120000.0000,
CAST(0x0000999C00000000 AS DateTime), 6)
INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget],
[StartDate], [Administrator]) VALUES (4, N'Economics', 200000.0000,
CAST(0x0000999C00000000 AS DateTime), 4)
INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget],
[StartDate], [Administrator]) VALUES (7, N'Mathematics', 250024.0000, CAST(0x0000999C00000000
AS DateTime), 3)
SET IDENTITY_INSERT [dbo].[Department] OFF
SET IDENTITY_INSERT [dbo].[Person] ON
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate],
[EnrollmentDate]) VALUES (1, N'Hu', N'Nan', NULL, CAST(0x0000A0BF00000000 AS
DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate],
[EnrollmentDate]) VALUES (2, N'Norman', N'Laura', NULL, CAST(0x0000A0BF00000000
AS DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate],
[EnrollmentDate]) VALUES (3, N'Olivotto', N'Nino', NULL,
CAST(0x0000A0BF00000000 AS DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate],
[EnrollmentDate]) VALUES (4, N'Anand', N'Arturo', NULL, CAST(0x0000A0BF00000000
AS DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate],
[EnrollmentDate]) VALUES (5, N'Jai', N'Damien', NULL, CAST(0x0000A0BF00000000
AS DateTime))
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate],
[EnrollmentDate]) VALUES (6, N'Holt', N'Roger', CAST(0x000097F100000000 AS
DateTime), NULL)
INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate],
[EnrollmentDate]) VALUES (7, N'Martin', N'Randall', CAST(0x00008B1A00000000 AS
DateTime), NULL)
SET IDENTITY_INSERT [dbo].[Person] OFF
SET IDENTITY_INSERT [dbo].[StudentGrade] ON
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (1, N'C1045', 1, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (2, N'C1045', 2, CAST(3.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (3, N'C1045', 3, CAST(2.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (4, N'C1045', 4, CAST(4.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (5, N'C1045', 5, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (6, N'C1061', 1, CAST(4.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (7, N'C1061', 3, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (8, N'C1061', 4, CAST(2.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (9, N'C1061', 5, CAST(1.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (10, N'C2021', 1, CAST(2.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (11, N'C2021', 2, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (12, N'C2021', 4, CAST(3.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (13, N'C2021', 5, CAST(3.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (14, N'C2042', 1, CAST(2.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (15, N'C2042', 2, CAST(3.50 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID],
[Grade]) VALUES (16, N'C2042', 3, CAST(4.00 AS Decimal(3, 2)))
INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade])
VALUES (17, N'C2042', 5, CAST(3.00 AS Decimal(3, 2)))
SET IDENTITY_INSERT [dbo].[StudentGrade] OFF
ALTER TABLE [dbo].[Course] WITH
CHECK ADD CONSTRAINT
[FK_Course_Department] FOREIGN KEY([DepartmentID])
REFERENCES [dbo].[Department] ([DepartmentID])
GO
ALTER TABLE [dbo].[Course] CHECK CONSTRAINT [FK_Course_Department]
GO
ALTER TABLE [dbo].[StudentGrade]
WITH CHECK ADD CONSTRAINT
[FK_StudentGrade_Student] FOREIGN KEY([StudentID])
REFERENCES [dbo].[Person] ([PersonID])
GO
ALTER TABLE [dbo].[StudentGrade] CHECK CONSTRAINT
[FK_StudentGrade_Student]
GO
A continuación, compile y ejecute lo siguiente:
using System;
using System.Data;
using System.Data.SqlClient;using System.Threading.Tasks;
class Program {
static class SqlHelper {
// Set the connection,
command, and then execute the command with non query.
public static Int32
ExecuteNonQuery(String connectionString, String commandText,
CommandType commandType,
params SqlParameter[] parameters) {
using (SqlConnection conn
= new SqlConnection(connectionString)) {
using (SqlCommand cmd
= new SqlCommand(commandText, conn)) {
// There're three
command types: StoredProcedure, Text, TableDirect. The TableDirect
// type is only for
OLE DB.
cmd.CommandType =
commandType;
cmd.Parameters.AddRange(parameters);
conn.Open();
return
cmd.ExecuteNonQuery();
}
}
}
// Set the connection,
command, and then execute the command and only return one value.
public static Object
ExecuteScalar(String connectionString, String commandText,
CommandType commandType,
params SqlParameter[] parameters) {
using (SqlConnection conn = new
SqlConnection(connectionString)) {
using (SqlCommand cmd
= new SqlCommand(commandText, conn)) {
cmd.CommandType =
commandType;
cmd.Parameters.AddRange(parameters);
conn.Open();
return
cmd.ExecuteScalar();
}
}
}
// Set the connection,
command, and then execute the command with query and return the reader.
public static SqlDataReader
ExecuteReader(String connectionString, String commandText,
CommandType commandType,
params SqlParameter[] parameters) {
SqlConnection conn = new
SqlConnection(connectionString);
using (SqlCommand cmd =
new SqlCommand(commandText, conn)) {
cmd.CommandType = commandType;
cmd.Parameters.AddRange(parameters);
conn.Open();
// When using
CommandBehavior.CloseConnection, the connection will be closed when the
// IDataReader is closed.
SqlDataReader reader =
cmd.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
}
}
}
static void Main(string[] args)
{
String connectionString =
"Data Source=(local);Initial Catalog=MySchool;Integrated
Security=True;Asynchronous Processing=true;";
CountCourses(connectionString,
2012);
Console.WriteLine();
Console.WriteLine("Following result is the departments that started
from 2007:");
GetDepartments(connectionString,
2007);
Console.WriteLine();
Console.WriteLine("Add
the credits when the credits of course is lower than 4.");
AddCredits(connectionString,
4);
Console.WriteLine();
Console.WriteLine("Please press any key to exit...");
Console.ReadKey();
}
static void CountCourses(String
connectionString, Int32 year) {
String commandText =
"Select Count([CourseID]) FROM [MySchool].[dbo].[Course] Where
Year=@Year";
SqlParameter parameterYear =
new SqlParameter("@Year", SqlDbType.Int);
parameterYear.Value
= year;
Object oValue =
SqlHelper.ExecuteScalar(connectionString, commandText, CommandType.Text,
parameterYear);
Int32 count;
if
(Int32.TryParse(oValue.ToString(), out count))
Console.WriteLine("There
{0} {1} course{2} in {3}.", count > 1 ? "are" :
"is", count, count > 1 ? "s" : null, year);
}
// Display the Departments that
start from the specified year.
static void
GetDepartments(String connectionString, Int32 year) {
String
commandText = "dbo.GetDepartmentsOfSpecifiedYear";
// Specify the year of
StartDate
SqlParameter parameterYear =
new SqlParameter("@Year", SqlDbType.Int);
parameterYear.Value
= year;
// When the direction of
parameter is set as Output, you can get the value after
// executing
the command.
SqlParameter parameterBudget
= new SqlParameter("@BudgetSum", SqlDbType.Money);
parameterBudget.Direction
= ParameterDirection.Output;
using (SqlDataReader reader
= SqlHelper.ExecuteReader(connectionString, commandText,
CommandType.StoredProcedure,
parameterYear, parameterBudget)) {
Console.WriteLine("{0,-20}{1,-20}{2,-20}{3,-20}",
"Name", "Budget", "StartDate",
"Administrator");
while (reader.Read()) {
Console.WriteLine("{0,-20}{1,-20:C}{2,-20:d}{3,-20}",
reader["Name"],
reader["Budget"], reader["StartDate"],
reader["Administrator"]);
}
}
Console.WriteLine("{0,-20}{1,-20:C}",
"Sum:", parameterBudget.Value);
}
// If credits of course is lower
than the certain value, the method will add the credits.
static void AddCredits(String
connectionString, Int32 creditsLow) {
String commandText =
"Update [MySchool].[dbo].[Course] Set Credits=Credits+1 Where
Credits<@Credits";
SqlParameter
parameterCredits = new SqlParameter("@Credits", creditsLow);
Int32 rows =
SqlHelper.ExecuteNonQuery(connectionString, commandText, CommandType.Text,
parameterCredits);
Console.WriteLine("{0}
row{1} {2} updated.", rows, rows > 1 ? "s" : null, rows >
1 ? "are" : "is");
}
}
2. Resumen
Puede utilizar la clase System.Data.SqlClient.SqlCommand
para cargar los resultados de las consultas de lenguaje de marcado Extensible
(XML) de SQL de Microsoft SQL Server a un objeto System.Xml.XmlReader . Puede utilizar
este método para ejecutar el servidor para consultas XML y ejecutar consultas
que devuelven datos XML bien formados como texto.
También este objeto permite:
Especificar el tipo de comando mediante la propiedad
CommandType antes de la ejecución para optimizar el rendimiento.
Controlar si el proveedor guarda una versión preparada (o
compilada) del comando antes de la ejecución mediante la propiedad Prepared.
Establecer el número de segundos que esperará un proveedor
para la ejecución de un comando mediante la propiedad CommandTimeout.
3. Summary
You
can use the System.Data.SqlClient.SqlCommand class to load the results of
Microsoft SQL Server Extensible Markup Language (XML) query queries to a
System.Xml.XmlReader object. You can use this method to run the server for XML
queries and run queries that return well-formed XML data as text.
This
object also allows:
Specify the type of
command using the CommandType property before execution to optimize
performance.
Check if the supplier
saves a prepared (or compiled) version of the command before execution through
the Prepared property.
Establish the number of
seconds that a provider will wait for the execution of a command through the
CommandTimeout property.
4. Recomendaciones
Éste método no está disponible en el proveedor administrado
de OLE DB .NET (es específico del proveedor administrado de .NET de SQL Server)
y no funciona con una base de datos de SQL 7.0.
La lista siguiente describe el hardware, software,
infraestructura de red y service packs recomendados que necesita: Otro sistema
operativo de Microsoft que puede alojar a SQL Server 2000, Windows 2000 Server
o Microsoft Windows NT 4.0 Server.
Utilizamos el Objeto SqlCommand solamente cuando
necesitamos ejecutar un tipo de sentencia Sql a la base de datos.
5. Conclusiones
Los comandos contienen la información que se envía a una
base de datos y se representan mediante clases específicas de un proveedor,
como SQLCommand. Un comando podría ser una llamada a un procedimiento almacenado,
una instrucción UPDATE o una instrucción que devuelve resultados. También es
posible utilizar parámetros de entrada o de resultados y devolver valores como
parte de la sintaxis del comando.
No podrás utilizar el Objeto SqlCommand cuando necesitas
ejecutar más de un tipo de sentencia Sql o si trabajarás en escenarios
desconectados.
Éste objeto permite: Especificar el tipo de comando
mediante la propiedad CommandType antes de la ejecución para optimizar el
rendimiento.
6. Apreciación del Equipo
Cuando se crea
una instancia de SqlCommand,
las propiedades de lectura y escritura se establecen en sus valores iniciales.
Un SqlCommand se utiliza cuando necesitas
ejecutar un tipo de sentencia Sql a la base de datos (los tipos pueden ser:
Delete, Update, Insert o Select).
7. Glosario de Términos
Abstraction (abstracción). Característica esencial de un
objeto que lo diferencia de otros objetos.
SERVER (SERVIDOR): Un objeto que proporciona servicios
que se utilizan por otros objetos. Los objetos que utilizan los servicios son clientes.
Abstract class (clase abstracta): Una clase abstracta
actúa como una plantilla de otras clases. Normalmente se utiliza como la raíz
de una jerarquía de clases.
Object (objeto): Combinación de datos y colección de
operaciones que actúan sobre los datos. En c++, una instancia de una clase (un tipo
objeto). Variable: Posición de almacenamiento que puede contener diferentes
valores.
Void (C++): Un nombre de un tipo utilizado para indicar
que una función no devuelve ningún valor, esto es, un procedimiento.
Void keyword (palabra reservada void): Palabra reservada
que indica tipo desconocido o ningún tipo. Un procedimiento es una función que devuelve
void.
8. Linkografía o Bibliografía
Suscribirse a:
Comentarios (Atom)