我正在使用XML创建动态SQL查询。 我需要使用运算符IN,但不能使其与倍数值一起使用。
在这里说明我的事情是有效的:
using System;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
using v = DocumentFormat.OpenXml.Vml;
using ovml = DocumentFormat.OpenXml.Vml.Office;
using System.IO;
using System.Drawing;
class Utility
{
public static void CreatePackage(string containingDocumentPath, string embeddedDocumentPath)
{
using (WordprocessingDocument package =
WordprocessingDocument.Create(containingDocumentPath,
WordprocessingDocumentType.Document))
{
AddParts(package, embeddedDocumentPath);
}
}
private static void AddParts(WordprocessingDocument parent,
string embeddedDocumentPath)
{
var mainDocumentPart = parent.AddMainDocumentPart();
GenerateMainDocumentPart().Save(mainDocumentPart);
var embeddedPackagePart =
mainDocumentPart.AddNewPart<EmbeddedPackagePart>(
"application/vnd.openxmlformats-" +
"officedocument.spreadsheetml.sheet",
"rId1");
GenerateEmbeddedPackagePart(embeddedPackagePart,
embeddedDocumentPath);
var imagePart =
mainDocumentPart.AddNewPart<ImagePart>(
"image/x-emf", "rId2");
GenerateImagePart(imagePart);
}
private static Document GenerateMainDocumentPart()
{
var element =
new Document(
new Body(
new Paragraph(
new Run(
new Text(
"This is the containing document."))),
new Paragraph(
new Run(
new Text(
"This is the embedded document: "))),
new Paragraph(
new Run(
new EmbeddedObject(
new v.Shape(
new v.ImageData()
{
Title = "",
RelationshipId = "rId2"
}
)
{
Id = "_x0000_i1025",
Style = "width:76.5pt;height:49.5pt",
},
new ovml.OleObject()
{
Type = ovml.OleValues.Embed,
ProgId = "Excel.Sheet.12",
ShapeId = "_x0000_i1025",
DrawAspect = ovml.OleDrawAspectValues.Icon,
ObjectId = "_1299573545",
Id = "rId1"
}
)
)
)
)
);
return element;
}
public static void GenerateEmbeddedPackagePart(OpenXmlPart part,
string embeddedDocumentPath)
{
byte[] embeddedDocumentBytes;
// The following code will generate an exception if an invalid
// filename is passed.
using (FileStream fsEmbeddedDocument =
File.OpenRead(embeddedDocumentPath))
{
embeddedDocumentBytes =
new byte[fsEmbeddedDocument.Length];
fsEmbeddedDocument.Read(embeddedDocumentBytes, 0,
embeddedDocumentBytes.Length);
}
using (BinaryWriter writer =
new BinaryWriter(part.GetStream()))
{
writer.Write(embeddedDocumentBytes);
writer.Flush();
}
}
public static void GenerateImagePart(OpenXmlPart part)
{
using (BinaryWriter writer = new BinaryWriter(part.GetStream()))
{
writer.Write(System.Convert.FromBase64String(EmbedExcelIntoWordDoc.Properties.Resource1.BASE64_STRING_EXCEL_ICON));
writer.Flush();
}
}
}
参数 @IncludedListB 在C#中以字符串形式构建
exec sp_executesql N'SELECT * FROM commercial_element WHERE specific_info IN (@IncludedListB)
',N'@IncludedListB nvarchar(30)',@IncludedListB='BAR'
我想做的是在运算符IN中传递多个参数:
filter.IncludedListB = 'BAR';
像这样构建:
exec sp_executesql N'SELECT * FROM commercial_element WHERE specific_info IN (@IncludedListB)
',N'@IncludedListB nvarchar(30)',@IncludedListB='''BAR'',''BSO'''
仅关注SQL为什么第二个查询不起作用?我会为C#弄清楚。