表示要对 SQL Server 数据库执行的一个 Transact-SQL 语句或存储过程。无法继承此类。

命名空间: System.Data.SqlClient

程序集: System.Data(在 System.Data.dll 中)

C#:

public sealed class SqlCommand : DbCommand, ICloneable

当创建 SqlCommand 的实例时,读/写属性将被设置为它们的初始值。

您可以重置 CommandText 属性并重复使用 SqlCommand 对象。但是,在执行新的命令或先前命令之前,必须关闭 SqlDataReader。如果执行 SqlCommand 的方法生成 SqlException,那么当严重级别小于等于 19 时,SqlConnection 将仍保持打开状态。当严重级别大于等于 20 时,服务器通常会关闭 SqlConnection。但是,用户可以重新打开连接并继续。

其中,str是数据连接字串,用来初始化Connection对象,说明如何连接数据库,当数据库连接完毕后,可以使用Open方法打开数据连接。完成数据库连接后,需创建一个新的Command对象,示例代码如下所示。

SqlCommand cmd = new SqlCommand("insert into mynews value ('插入一条新数据')", conn);

Command对象的构造函数的参数有两个,一个是需要执行的SQL语句,另一个是数据库连接对象。创建Command对象后,就可以执行SQL命令,执行后完成并关闭数据连接,示例代码如下所示。

1.CommandText

获取或设置要对数据源执行的Transact—SQL语句或存储过程。[1]

2. CommandType

获取或设置一个值,该值指示如何解释CommandText属性。

3.Connection

获取或设置SqlCommand的实例使用的SqlConnection。

4.CommandTimeOut

获取或设置在终止执行命令的尝试并生成错误之前的等待时间。

刚刚查询:sqlcommand HttpCore 仰望苍天 Pattern unsigned ColorStone ScienceDirect exploit Principles Interface parallel persistent Project RAZORBACK OpenMobileTerminalPlatform Fastopen efficiency explicit Micro-USB Radisson Integration ClinicalKey software Locksmith Exposition Collateral Emphasis Semantics Judgment gradient Explorer Unitree Extralight thread- ProCAST Windows component Flamenca Knightmare Filmore principles squeezing surface flotation Sherpath Study Reading Coupling capitulum Peruvian Mathematical fication Guilder effects squeezed Prodigy Exquisite technology Prophoca Halogen Nlsfunc Telefonica electro Optical Vandersall Colburn Scheele creating flat-worm connected Propelled globalization HISTORY Recordset conceive Records especially decides services improved Manufacturing
友情链接: 知道 电影 百科 好搜 问答 微信 值得买 巨便宜 天天特价 洛阳汽车脚垫 女装 女鞋 母婴 内衣 零食 美妆 汽车 油价 郑州 北京 上海 广州 深圳 杭州 南京 苏州 武汉 天津 重庆 成都 大连 宁波 济南 西安 石家庄 沈阳 南阳 临沂 邯郸 保定 温州 东莞 洛阳 周口 青岛 徐州 赣州 菏泽 泉州 长春 唐山 商丘 南通 盐城 驻马店 佛山 衡阳 沧州 福州 昆明 无锡 南昌 黄冈 遵义
© 2026 haodianxin 百科 消耗时间:0.002秒 内存0.8MB