public DataSet SelectSqlSrvRows ( DataSet myDataSet, string myConn,
string query, string myTableName ) {
SqlConnection myConn = new SqlConnection ( myConn );
SqlDataAdapter myDataAdapter = new SqlDataAdapter ( );
myDataAdapter.SelectCommand = new SqlCommand ( query, myConn );
SqlCommandBuilder custCB = new SqlCommandBuilder ( myDataAdapter );
myConn.Open ( );
DataSet myDataSet = new DataSet ( );
myDataAdapter.Fill ( myDataSet, "Customers" );
// code to modify data in dataset here
// without the SqlCommandBuilder this line would fail
myDataAdapter.Update ( myDataSet, "Customers" );
myConn.Close ( );
}
Public Function SelectSqlSrvRows ( myDataSet As DataSet, myConn As String, _
query As String, myTableName As String ) As DataSet
Dim myConn As New SqlConnection ( myConn )
Dim myDataAdapter As New SqlDataAdapter ( )
myDataAdapter.SelectCommand = New SqlCommand ( query, myConn )
Dim custCB As SqlCommandBuilder = New SqlCommandBuilder ( myDataAdapter )
myConn.Open ( )
Dim myDataSet As DataSet = New DataSet
myDataAdapter.Fill ( myDataSet, "Customers" )
' code to modify data in DataSet here
' without the SqlCommandBuilder this line would fail.
myDataAdapter.Update ( myDataSet, "Customers" )
myConn.Close ( )
End Function |