打印本文 打印本文 关闭窗口 关闭窗口
第三课 SqlCommand对象(翻译)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数14792  更新时间:2007/11/14 13:12:47  文章录入:mintao  责任编辑:mintao
中,SqlConnection对象在SqlCommandDemo结构中被实体化。这是可以的,因为当CLR垃圾回收器执行的时候对象本身会被清除。重要的是在我们做完了工作之后要关闭连接。此程序在每一个方法中打开在一个try语句块的连接,并且在finally语句块中关闭它。

The ReadData method displays the contents of the CategoryName column of the Categories table.  We use it several times in the Main method to show the current status of the Categories table, which changes after each of the insert, update, and delete commands.  Because of this, it is convenient to reuse to show you the effects after each method call.

ReadData方法现实Categories表中的CategoryName列的内容。我们在Main方法中使用它许多次来现实Categorie表的当前状态,它在每一个insertupdatedelete命令之后都会改变。因为这样,它能够在每一个函数被调用之后重用来查看效果。

Summary

总结

A SqlCommand object allows you to query and send commands to a data base.  It has methods that are specialized for different commands.  The ExecuteReader method returns a SqlDataReader object for viewing the results of a select query.  For insert, update, and delete SQL commands, you use the ExecuteNonQuery method.  If you only need a single aggregate value from a query, the ExecuteScalar is the best choice.

SqlCommand

 << 上一页  [11] [12] [13] [14] [15]  下一页

打印本文 打印本文 关闭窗口 关闭窗口