下面的示例使用 SqlCommand 以及 SqlDataAdapter 和 SqlConnection 从数据源选择行。给该示例传递一个初始化的 DataSet、一个连接字符串、一个查询字符串(它是一个 Transact-SQL SELECT 语句)和一个包含数据库表名称的字符串。然后该示例创建一个 SqlCommandBuilder。[Visual Basic] 
Public Function SelectSqlSrvRows(myDataSet As DataSet, myConnection As String, mySelectQuery As String, myTableName As String) As DataSet
    Dim myConn As New SqlConnection(myConnection)
    Dim myDataAdapter As New SqlDataAdapter()
    myDataAdapter.SelectCommand = New SqlCommand(mySelectQuery, myConn)
    Dim custCB As SqlCommandBuilder = New SqlCommandBuilder(myDataAdapter)    myConn.Open()    Dim custDS As DataSet = New DataSet
    myDataAdapter.Fill(custDS, "Customers")    ' Code to modify data in DataSet here     ' Without the SqlCommandBuilder this line would fail.
    myDataAdapter.Update(custDS, "Customers")    myConn.Close()
End Function 'SelectSqlSrvRows
[C#] 
public DataSet SelectSqlSrvRows(DataSet myDataSet,string myConnection,string mySelectQuery,string myTableName) {
    SqlConnection myConn = new SqlConnection(myConnection);
    SqlDataAdapter myDataAdapter = new SqlDataAdapter();
    myDataAdapter.SelectCommand = new SqlCommand(mySelectQuery, myConn);
    SqlCommandBuilder custCB = new SqlCommandBuilder(myDataAdapter);    myConn.Open();    DataSet custDS = new DataSet();
    myDataAdapter.Fill(custDS, "Customers");    //code to modify data in dataset here    //Without the SqlCommandBuilder this line would fail
    myDataAdapter.Update(custDS, "Customers");    myConn.Close();    return custDS;
 }