| In the example above, we instantiate a SqlCommand object, passing the command string and connection object to the constructor. Then we obtain a SqlDataReader object by calling the ExecuteReader method of the SqlCommand object, cmd.
在上面的示例中,我们通过传递命令字符串核连接对象到构造函数的方式实体化了SqlCommand对象。然后我们通过SqlCommand对象cmd调用ExecuteReader方法得到了SqlDataReader对象。
This code is part of the ReadData method of Listing 1 in the Putting it All Together section later in this lesson.
这些代码是表1中ReadData方法的一部分,我们将在后面集中介绍。
Inserting Data
插入数据
To insert data into a data base, use the ExecuteNonQuery method of the SqlCommand object. The following code shows how to insert data into a data base table:
要对数据库插入数据,使用SqlCommand对象的ExecuteNonQuery方法。下面的代码显示了如何向数据库表插入数据:
// prepare command string string insertString = @" insert into Categories (CategoryName, Description) values (''''Miscellaneous'''', ''''Whatever doesn''''''''t fit elsewhere'' 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |