将戳转换为varchar并在c#中使用它

时间:2014-03-04 14:03:33

标签: c# sql-server

我创建了存储过程,使用最后一个标记使用C#服务将表中的数据从主数据库同步到分支。在存储过程中,我将主数据库的标记转换为varchar 从参数中选择@CurrentStamp = convert(varchar,value),其中id = 3 这个标记我应该在C#中作为输出得到它将它作为参数发送到分支中的存储过程保存应该同步的数据,然后将此戳记保存在参数表中作为varchar。全部通过测试而不使用肥皂服务。当我尝试在soap服务中使用它时会抛出异常十六进制值0x00,是一个无效字符。任何帮助,请我尝试将其转换为varbinary但它不断将标记更改为另一个值。如果有人知道如何让XML无异常地读取这些值,请帮助。

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

0 个答案:

没有答案