FamilyService.FamilyService fs = new FamilyService.FamilyService();
DataSet ds = fs.GetFamilyToSynchronize(Current.LoggedUserSchool.ID, stamp, out currentStamp);
-
public static DataSet GetFamilyToSynchronize(int schoolID, string stamp, out string CurrentStamp)
{
DataTable dtFamilyToSynchronize = new DataTable();
DataTable dtFamilyPhones = new DataTable();
CurrentStamp = "";
DataSet ds = new DataSet();
try
{
using (DataBaseClass db = new DataBaseClass())
{
db.Connect();
SqlCommand command = db.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "GetFamilyToSynchronize";
command.Parameters.AddWithValue("@SchoolID", schoolID);
command.Parameters.AddWithValue("@Stamp", stamp);
command.Parameters.AddWithValue("@CurrentStamp", CurrentStamp);
command.Parameters["@CurrentStamp"].Direction = ParameterDirection.InputOutput;
command.Parameters["@CurrentStamp"].Size = 255;
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds);
CurrentStamp = command.Parameters["@CurrentStamp"].Value.ToString();
}
}
catch (Exception ex){Logger.LogException(ex);}
return ds;
}
SQL存储过程
GO
ALTER Proc [dbo].[GetFamilyToSynchronize] (@SchoolID int , @Stamp varchar(255) = null, @CurrentStamp varchar(255) output) as
select @CurrentStamp = convert(varchar, value) from parameter where id = 3
SELECT f.*
into #tmpFamily
FROM [Family] f
inner join fatherschools fs on fs.FamilyID = f.ID
where f.id =f.fatherlinkid --not in (select FatherLinkID from family )
and schoolID = @SchoolID
and (@Stamp is null or f.stamp> convert(timestamp, isnull(@Stamp,'')))
select distinct f.id, phonetypeid,phonenumber, t.FatherLinkID
from familyphones f
inner join #tmpFamily t on t.ID = f.FamilyID
select * from #tmpFamily