打印本文 打印本文 关闭窗口 关闭窗口
第三课 SqlCommand对象(翻译)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数14794  更新时间:2007/11/14 13:12:47  文章录入:mintao  责任编辑:mintao
为了执行此命令,我们简单的对SqlCommand实体cmd调用ExecuteNonQuery方法。

This code is part of the InsertData method of Listing 1 in the Putting it All Together section later in this lesson.

这段代码是表1InsertData方法的一部分,我们将在后面集中介绍。

Updating Data

更新数据

The ExecuteNonQuery method is also used for updating data.  The following code shows how to update data:

ExecuteNonQuery方法同样用来更新数据。下面的代码显示了如何更新数据:

// prepare command string
 
string updateString = @"
     update Categories
     set CategoryName = ''''Other''''
     where CategoryName = ''''Miscellaneous''''";
 
 // 1. Instantiate a new command with command text only
 
SqlCommand cmd = new SqlCommand(updateString);
 
 // 2. Set the Connection property
 
cmd.Connection = conn;
 
 // 3. Call ExecuteNonQuery to send command
 
cmd.ExecuteNonQuery();

Again, we put the SQL command into a string variable, but this time we used a different SqlCommand constructor that takes only the command.  In step 2, we assign the SqlConnection object, conn, to the Connection property of the SqlCommand object, cmd. 

再一次,我们将SQL命令赋给字符串变量,但是这次我们使用了不同的

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ...  下一页 >> 

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