如何在SQL Server的列中插入长字符串值

时间:2014-12-10 10:31:20

标签: c# sql .net sql-server

INSERT INTO [Bitflow].[dbo].[GlobalConfiguration]
           ([Key]
           ,[Value]
           ,[Description]
           ,[DATE_LAST_UPDATED]
           ,[DATE_CREATED])
     VALUES
           ('OPERATIONS_BES_USERS_SQL_QUERY_01'
           ,'select DisplayName,EmailAddress,RelayServer, ModelName, PhoneNumber, PIN, 

HomeNetwork, ActiveCarrier, ICCID, 
             convert(varchar(10),CreationDate, 101)CreationDate,convert(varchar(10),ActivationDate, 

101)ActivationDate, 
             MsgsForwarded, MsgsSent,convert(varchar(10),LastFwdDate, 101)LastFwdDate,convert

(varchar(10),LastSentDate, 101)LastSentDate, 
             CurrentPolicyName, ServiceName from TEMP_BESselect 

DisplayName,EmailAddress,RelayServer, ModelName, PhoneNumber, PIN, HomeNetwork, 

ActiveCarrier, ICCID, 
             convert(varchar(10),CreationDate, 101)CreationDate,convert(varchar(10),ActivationDate, 

101)ActivationDate, 
             MsgsForwarded, MsgsSent,convert(varchar(10),LastFwdDate, 101)LastFwdDate,convert

(varchar(10),LastSentDate, 101)LastSentDate, 
             CurrentPolicyName, ServiceName from TEMP_BES'
           ,'Query for respective Bes Server'
           ,CAST(0x0000A2A600000000 AS DateTime), CAST(0x0000A2A600000000 AS DateTime))
GO

第二个值是一个巨大的字符串,通过nvarchar(max)存储它很多空格,而从c#代码中检索想要删除它。什么是兼容的数据类型来检索C#中nvarchar(max)的值?我想要检索此值

2 个答案:

答案 0 :(得分:0)

我认为您可以使用常见的SqlCommand

并且对于您的第二个参数,您可以执行以下操作

cmd.Parameters.Add("@Value", SqlDbType.VarChar);
cmd.Parameters["@Value"].Value = longString;

其中longString是您的查询参数

答案 1 :(得分:0)

我猜你是通过C#应用程序生成上述查询。使用以下内容消除多个空格:

http://msdn.microsoft.com/en-us/library/xwewhkd1%28v=vs.110%29.aspx

string input = "This is   text with   far  too   much     whitespace.";
string pattern = "\\s+";
string replacement = " ";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);