首页 \ 问答 \ 在ADO.NET中将[for xml auto,elements]读入DataTable(Read [for xml auto, elements] into DataTable in ADO.NET)

在ADO.NET中将[for xml auto,elements]读入DataTable(Read [for xml auto, elements] into DataTable in ADO.NET)

我有MS SQL Server存储过程返回XML(它使用SELECT with for xml auto,elements

我尝试将其读入DataTable:

            DataTable retTable = new DataTable();
            SqlCommand comm = new SqlCommand("exec MySP", connection);
            SqlDataAdapter da = new SqlDataAdapter(comm);
            connection.Open();
            da.Fill(retTable); 

但retTable包含12行,SQL Server返回分隔的完整xml。

如何从DB读取XML到DataTable对象? 谢谢!


I have MS SQL Server stored procedure that returns XML (it uses SELECT with for xml auto, elements)

I tried read it into DataTable:

            DataTable retTable = new DataTable();
            SqlCommand comm = new SqlCommand("exec MySP", connection);
            SqlDataAdapter da = new SqlDataAdapter(comm);
            connection.Open();
            da.Fill(retTable); 

but retTable contains 12 rows with separated full xml thar SQL Server returns.

How can I read that XML from DB into DataTable object? Thanks!


原文:https://stackoverflow.com/questions/4240126
更新时间:2023-02-13 13:02

最满意答案

你所描述的是K最佳指派问题的一个特例 - 事实上,Katta G. Murty在随后的1968年论文“ 按增加成本的顺序排列所有指配的算法 ”中提出了解决这个问题的方法运筹学16(3):682-687。

看起来实际上有相当数量的实现,至少在Java和Matlab中,可以在网上获得(参见例如此处)


What you describe is a special case of the K best assignments problem -- there was in fact a solution to this problem proposed by Katta G. Murty in the following 1968 paper "An Algorithm for Ranking all the Assignments in Order of Increasing Cost." Operations Research 16(3):682-687.

Looks like there are actually a reasonable number of implementations of this, at least in Java and Matlab, available on the web (see e.g. here.)

相关问答

更多
  • 我刚试过: pip install munkres 它的工作。 在这里你可以找到关于如何使用它的简短说明。 我试图安装“匈牙利语”时出错。 I just tried: pip install munkres and it worked. Here you can find a short explanation on how to use it. I got an error trying to install "hungarian".
  • 如果所有变量(结构和逻辑)都是非负的(即x>=0且松弛s>=0 ),那么所有非基本变量都等于零。 当它们被固定为零时,我们只需要解决m基本变量。 基本上我们必须解决 A x = b 不幸的是,这是一个非方形的方程组(加入松弛后,我们总是有比列更多的列)。 在LP中,我们可以形成一个基本的解决方案并将其划分 B x_B + N x_N = b 在设置x_N = 0我们只有一个具有解的线性方程组的平方系统: x_B = inv(B) b 有一个基本定理说,我们可以将搜索限制为只有基本的解决方案,即可以分解 ...
  • 你可以在你的例子中覆盖矩阵中的零,只有四行:列b,行A,行B,行E. 下面是该算法的逐步演练,如截至6月25日的维基百科文章所示,适用于您的示例: a b c d e A 0 7 0 0 0 B 0 8 0 0 6 C 5 0 7 3 4 D 5 0 5 9 3 E 0 4 0 0 9 第一步:每行的最小值为零,所以减法没有效果。 我们试图分配任务,使每项任务都以零成本执行,但事实证明这是不可能的。 继续下一步。 第2步: ...
  • 如果我们使用固定位数的整数表示(例如32位整数),那么我们可以推理如下: 在任何给Add调用中,假设y以n个零值位结束。 (例如,如果y的二进制表示以1000结尾,那么n是3.) 那么x & y 以至少n个零值位结束,因为无论y在哪里,它都将具有零值位。 并且(x & y) << 1以至少n + 1个零值位结束,因为它将一切向左移动并在末尾添加一个零位。 (例外:如果y == 0 ,则零位的数量是“最大值”,并且这个移位是无操作的,但是在那种情况下,我们不会到达else的)。 因此,每次递归调用都会将尾随零 ...
  • 假设您将最大分配数量的成本降至最低,请修改Munkres算法以使用以下算术和顺序规则的数字对(a, b) : (a, b) + (c, d) = (a + c, b + d) -(a, b) = (-a, -b) (a, b) < (c, d) if and only if a < c or (a = c and b < d). 使用(0, 0)而不是0 。 成本(a, b)的解释是a是不允许的分配的数量,而b是允许的分配的总成本。 因此,每个成本c被映射到(0, c) ,并且每个不允许的赋值映射到(1, ...
  • 这是一个调度/优化问题,所以关键问题是“你试图最大化哪个数量”? 我想你会希望最大限度地发挥所有志愿者在没有冲突的情况下工作的总时数,这取决于每个志愿者的时间安排约束。 你还提到优先考虑有更多经验的志愿者,所以听起来好像你在说“有些志愿者比其他人更喜欢 ”。 这是一个经典的双方匹配问题 。 参见Steven Skiena编写的算法设计手册 (第2版)的egp498。 基本的方法是构造一个图表,其顶点代表志愿者集合,以及您尝试填充的时间段集合。 Edges将志愿者链接到有效的时间段。 那么最佳解决方案是最大可 ...
  • 你所描述的是K最佳指派问题的一个特例 - 事实上,Katta G. Murty在随后的1968年论文“ 按增加成本的顺序排列所有指配的算法 ”中提出了解决这个问题的方法。运筹学16(3):682-687。 看起来实际上有相当数量的实现,至少在Java和Matlab中,可以在网上获得(参见例如此处) 。 What you describe is a special case of the K best assignments problem -- there was in fact a solution to ...
  • 您的输入大小为N * M,因此您无法获得更好的时间复杂度 - 您必须阅读所有输入。 最初我误解了这个问题并在下面发布了算法; 它的时间复杂度仅略大于输入大小( O(nm log nm) ),但是当你想要最大限度地增加会议中的人数时,如果他们不能同时满足所有人,则可以解决更一般的情况。 1. Merge periods (a, b), (b, c) into (a, c) 2. Forget periods shorter than 2 hours 3. Transform your input into l ...
  • 这基本上是一个网络流量问题。 我将为您的示例绘制容量图(未标记的弧具有无限容量)。 s是源, t是接收器。 >A------->1 1000/ |\ ^\ / | \ / \1000 / | \ / \ / | \ / 500 v s | /->2--->t \ \ / ^ \ \/ / \ /\ /500 1000\ / \ / ...
  • 假设课程1可容纳x_1学生,课程2可容纳x_2学生,...,课程5可容纳x_5学生,创建初始矩阵,课程1为x_1列,课程2为x_2列,...,x_5列当然5.在每个x_i列中复制每个学生对课程i的评分。 算法终止时将会有未分配的列,除非您的课程容量不超过您的学生数和未分配的行,除非您的课程容量不低于您的学生数。 Assuming that course 1 can accommodate x_1 students, course 2 can accommodate x_2 students, ..., co ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)