111,130
社区成员
发帖
与我相关
我的任务
分享
string temp = string.Empty;
temp = xxx;
temp.GetType();
//我这有个写好的方法
/// <summary>
/// 根据数据类型确定格式
/// </summary>
/// <param name="ob"></param>
/// <returns></returns>
private string ByType(object ob)
{
if(ob.GetType()==Type.GetType("System.DBNull"))
{
return "NULL";
}
if(ob.GetType()==Type.GetType("System.Decimal") ||ob.GetType()==Type.GetType("System.Double")||ob.GetType() == Type.GetType("System.Single"))
{
return ob.ToString();
}
else
{
return " '" + ChangeSTR(ob.ToString()) +"'";
}
}
/// <summary>
/// 替换字符串中单引号
/// </summary>
/// <param name="sourceStr">需要更改的字符串</param>
/// <returns>更改后的字符串</returns>
private string ChangeSTR(string sourceStr)
{
string resultSTR = string.Empty;
resultSTR = sourceStr.Replace("'","''");
return resultSTR;
}