Massaging data/parameters

Can I massage the data that comes from a DataTable on the server side and before it gets to the client.

And can I massage the parameters before they are fed to a DataTable/Command (again on the server side).

Could you please point me to an article that would describe this?

Thanks

Hello.

Sorry for the belated response.

The easiest solution to achieve this is to provide custom GetData method that allows to get resultset or result of the command before sending it back to the client.

Can I massage the data that comes from a DataTable on the server side and before it gets to the client.
Yes, it is possible to do such a thing. You need to create custom method for DataService (f.e. MyCustomGetDataMethod) and use the next implementation for it:

public Binary MyCustomGetDataMethod(string[] MyCustomDataTableNamesParam, int MyCustomIntegerParam)
 {
    . . .
    Binary result = new Binary();

    ServiceDataStreamer.InitializeStreamer(result, StreamerInitialization.Write);

    SchemaDataTable tableSchema;
    string tableName;

     try
     {
          for (int i = 0; i < MyCustomDataTableNamesParam.Length; i++)
          {
                tableName = MyCustomDataTableNamesParam[i];
                tableSchema = ServiceSchema.DataTables[tableName];
                int maxRecords = -1;

                string[] parNames = null;
                object[] parValues = null;

                IDataReader reader = null;
                try
                {
                      reader = ServiceSchema.NewDataReader(Connection, tableName, null /*as DynSelect*/ , null /*as DynWhere*/ , parNames, parValues);
                      ServiceDataStreamer.WriteDataReader(reader, tableSchema, maxRecords);
                }
                finally
               {
                      if (reader != null) reader.Close();
               }  
         }
    } 
    finally
    {
           ServiceDataStreamer.FinalizeStreamer();
    }
    . . .
    //result contains all the data for the client. You can use it before sending.
    return result;
 }

On the client side you need to change DataRequestCall.MethodName of RemoteDataAdapter to MyCustomGetDataMethod and the use RemoteDataAdapter as usually.

            remoteDataAdapter.DataRequestCall.ParameterByName("MyCustomIntegerParam").Value = 99;
            remoteDataAdapter.Fill(dsNorthwind);

And can I massage the parameters before they are fed to a DataTable/Command (again on the server side).
You need to create custom method for DataService (f.e. ExecuteCommandWithResultSet) and use the next implementation for it:

public int ExecuteCommandWithResultSet(string aCommandName, DataParameter[] aParameters)
 {
    int result = 0;
    if (!AllowDataAccess) new DAException("Data access has been disabled (ExecuteCommand)");
    if (!AllowExecuteCommands) new DAException("Execution of commands has been disabled (ExecuteCommand)");

    CheckConnection();

    string[] parNames = null;
    object[] parValues = null;

     if (aParameters != null)
     {
           //Here you catch parameters sent by client side 
           Int32 cnt = aParameters.GetLength(0);
           parNames = new string[cnt];
           parValues = new object[cnt];
           for (int i = 0; i < cnt; i++)
           {
                parNames[i] = aParameters[i].Name;
                parValues[i] = aParameters[i].Value;
           }
     }   
     IDbCommand cmd = ServiceSchema.NewCommand(Connection, aCommandName, parNames, parValues);
     result = Convert.ToInt32(cmd.ExecuteScalar());
     return result;
 }

On the client side you need to drop RemoteCommand object, change it’s property ExecuteCall.MethodName to ExecuteCommandWithResultSet and execute appropriate schema command as follows:

            DataParameter[] inParams = new DataParameter[2] {new DataParameter("Beginning_Date","1900-01-01"),new DataParameter("Ending_Date","2010-01-01")};
            DataParameter[] outParams = null;
            var res = remoteCommand.Execute("Sales by Year", inParams, out outParams);
            MessageBox.Show(res.ToString());

Please take a look at the attachment archive. It contains the project that implements methods above and shows simple work with custom functions.

Hope this helps.