我有一个SQL Server存储过程,返回多个结果.存储过程的主体可能如下所示:
SELECT * FROM tableA;
SELECT * FROM tableB;
SELECT * FROM tableC;
Run Code Online (Sandbox Code Playgroud)
在这种情况下,存储过程返回3个结果集.其他存储过程可能返回例如1,0或任何数量的结果集.每个结果集中可能包含0行或更多行.加载这些时,我需要调用IDataReader.NextResult()以在结果集之间导航.
如何可靠地获取C#中的结果集(不是行数)?
我试着解释我的问题.
我有自己的Windows服务(WS).这个WS引用Helpers.dll.Helpers.dll它是我自己的类库,有几个引用.其中一个参考是System.Web.Mvc.dll.
例如,如果我在Helpers.dll我的WS上添加引用,那么所有引用Helpers.dll都不会被添加到WS中.(在大多数情况下,这种行为是正确的,我认为)
我正在尝试Copy Local = True在Syste.Web.Mvc.dll(Helpers.csproj)上设置引用的内部属性
<Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
</Reference>
Run Code Online (Sandbox Code Playgroud)
但是,没有任何改变.
如果没有放在Helpers.dll中的引用,我的WS无法正常工作.
TypeInitializationException将被扔进rintume.(在尝试执行AppDomain.CurrentDomain.GetAssemblies()此程序集之一的静态构造函数中发生异常,Helpers.dll并且链接已启用System.Web.Mvc.dll)
如何使用此库的所有引用添加类库引用?
确切地说,我可以手动System.Web.Mvc.dll在WS项目中添加这个references(),我想通过设置或.config文件或其他方式来实现.
实际上,我使用下面的代码进行动态解析汇编:
无论如何,在解析程序集的第一个使用类之后,我在WS中得到了异常AssemblyHelpers- 我使用的是WS(这只放在Helpers项目的bin文件夹中,而不是在WS的 bin foder中).Helpers.dllSystem.Web.Mvc.dlldll
但是我的WS …
return false如果SP.ServerException被抛出,我需要防止记录.但在所有其他情况下,我也需要进行日志记录return false.
try
{
folder = GetFolderByRelativeUrl(folderRelativePath);
}
catch (SP.ServerException serverEx)
{
//if file is not found the logging is not need
if (serverEx?.Message == "File not found")
{
return false;
}
//how i can go from here
}
catch (Exception ex)
{
//to there
Log(ex.Message);
return false;
}
Run Code Online (Sandbox Code Playgroud)
我知道解决方案可能是
try
{
folder = GetFolderByRelativeUrl(folderRelativePath);
}
catch (Exception ex)
{
//if file is not found the logging is not need
if (!(ex is SP.ServerException …Run Code Online (Sandbox Code Playgroud) 我有一个单词和文字.我必须找到所有提出这个词的提案.你有什么主意吗?
piblic List<string> GetSnetences(string word)
{
// search all proposals that have the word
{
Run Code Online (Sandbox Code Playgroud) 我有一个集合(集合中有大于100K的自定义复杂项目,添加新项目的情况确实经常发生)。我只需要对它进行一次排序-在显示它之前。为了简化我的问题,可以说我有一个需要排序的整数集合:
private static void Main(string[] args)
{
var collection = new Collection<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
var list = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
var array = new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
// How to apply Array.Sort to Collection<T> ?
list.Sort(); //ok
Array.Sort(array); //ok
}
Run Code Online (Sandbox Code Playgroud)
基本list.Sort();用途Array.Sort<T>(this._items, index, count, comparer);
我该如何分类Collection<T> …
我的代码:
public class MyClass
{
private WdmEntities _context;
public List<T> GetTable<T>()
{
List<T> res = new List<T>();
_context = new DbEntities();
if (typeof(T) == typeof(tables))
res = _context.tables.ToList();//error cannot implicitly convert type
if (typeof(T) == typeof(columns))
res = _context.columns.ToList();//error cannot implicitly convert type
return res;
}
}
Run Code Online (Sandbox Code Playgroud)
我有来自EntityModel的表和列类型
但我得到编译错误:
cannot implicitly convert type
Run Code Online (Sandbox Code Playgroud)
如何更改我的代码以使其工作?
我想为文本创建一个Rectangle.但我不知道字符串的大小.现在我得到如下大小(对于带大写的字符串无效):
var textSize = e.Graphics.MeasureString(text, e.Appearance.Font);
Run Code Online (Sandbox Code Playgroud)
但是如果我的字符串是大写的,这个函数将返回错误的值.
如果字符串是大写的,如何获取字符串的大小?
下面的算法将十六进制转换为十进制,但我很困惑,这个解决方案是如何工作的?
public static int hex2decimal(String s) {
String digits = "0123456789ABCDEF";
s = s.toUpperCase();
int val = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
int d = digits.indexOf(c);
val = 16*val + d;
}
return val;
}
Run Code Online (Sandbox Code Playgroud)
在我发现这个之前,我只知道一种方法.我的意思是,每个人都知道:
你要转换的数字X*16^Y在哪里,X是数字Y的位置(从结尾到开始).
所以,如果你想转换DA145成十进制将...
*(5 * 16^0) + (4 * 16^1) + (1 * 16^2) + (10 * 16^3) + (13 * 16^4)*
Run Code Online (Sandbox Code Playgroud) 我有点困惑,如果每个块都有自己的大小,我应该如何通过块读取大文件(> 8GB).
如果我知道块大小,它看起来像下面的代码:
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, ProgramOptions.BufferSizeForChunkProcessing))
{
using (BufferedStream bs = new BufferedStream(fs, ProgramOptions.BufferSizeForChunkProcessing))
{
byte[] buffer = new byte[ProgramOptions.BufferSizeForChunkProcessing];
int byteRead;
while ((byteRead = bs.Read(buffer, 0, ProgramOptions.BufferSizeForChunkProcessing)) > 0)
{
byte[] originalBytes;
using (MemoryStream mStream = new MemoryStream())
{
mStream.Write(buffer, 0, byteRead);
originalBytes = mStream.ToArray();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是想象一下,我已经通过块读取大文件,对每个块进行了一些编码(在该操作被更改之后块的大小)并写入另一个新文件所有已处理的块.现在我需要做相反的操作.但我不知道确切的块大小.我有个主意.在处理完每个块之后,我必须在块字节之前写入新的块大小.像这样:
Number of block bytes
Block bytes
Number of block bytes
Block bytes
Run Code Online (Sandbox Code Playgroud)
所以在这种情况下,首先我需要做的是读取chunk的标题并准确地了解什么是块大小.我只读取和写入文件字节数组.但我有一个问题 - 如何看待chunk的标题?可能是标题必须包含一些边界?
我想从字符串中删除所有空格(仅限' '和'\t''\ r \n'应保留).但我有问题.
示例:如果我有
string test = "902322\t\r\n900657\t\r\n10421\t\r\n";
string res = test.Trim(); // res still "902322\t\r\n900657\t\r\n10421\t\r\n"
res = test.Trim('\t'); // res still "902322\t\r\n900657\t\r\n10421\t\r\n"
Run Code Online (Sandbox Code Playgroud)
但如果我有
string test = "902322\t";
Run Code Online (Sandbox Code Playgroud)
Trim()工作完美.为什么会这样?如何'\t从字符串使用Trim()方法中删除' ?