DSCustomer oDataSet = new DSCustomer(); oDataSet.Tables[0].Rows.Add(); DataTable oTable = oDataSet.Tables[0]; int iRowCount = oTable.Rows.Count - 1; DataRow oRow = oTable.Rows[iRowCount]; oRow["CustomerName"] = "Millard Filmore"; oRow["CreditLimit"] = 2520; SqlCommandBuilder oBuilder = new SqlCommandBuilder(oDataAdapter); oDataAdapter.Update(oDataSet, oDataSet.Tables[0].TableName);This throws an error because there is no data adapter. If works if I do:
string sSelectCommand = "select * from Customers where CustomerKey = 1"; SqlDataAdapter oDataAdapter = new SqlDataAdapter(sSelectCommand, oConnection);before hand. But my question is that this seems to be making a call into the DB just to save a new record.
>>/***************************************************** >> * Get the customer record >>******************************************************/ >> >>string sSelectCommand = "select * from Customers where CustomerKey = 1"; >> >>SqlDataAdapter oDataAdapter = new SqlDataAdapter(sSelectCommand, oConnection); >>DSCustomer oDataSet = new DSCustomer(); >>oDataAdapter.Fill(oDataSet, "DSCustomer"); >> >>/***************************************************** >> * Or Create a new blank data set record >>******************************************************/ >>//DSCustomer oDataSet = new DSCustomer(); >> >>// Add a blank row >>oDataSet.Tables[0].Rows.Add(); >> >> >>// Get a reference to the table >>DataTable oTable = oDataSet.Tables[0]; >> >>// Get the number of rows >>int iRowCount = oTable.Rows.Count - 1; >> >>// Get a reference to the new row >>DataRow oRow = oTable.Rows[iRowCount]; >> >>// Edit the column values >>oRow["CustomerName"] = "Someone Else"; >>oRow["CreditLimit"] = 15; >> >>// Save the changes to the dataset >>oDataSet.AcceptChanges(); >> >>// Create a command builder. >>SqlCommandBuilder oBuilder = new SqlCommandBuilder(oDataAdapter); >> >>// Update the changes to the backend >>oDataAdapter.Update(oDataSet, oDataSet.Tables[0].TableName); >> >>>