将带有随机列的数据表传递给存储过程 [英] Passing datatable with random columns to stored procedure

查看:63
本文介绍了将带有随机列的数据表传递给存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将DataTable传递给存储过程的最有效方法是使用用户定义的表类型。但它要求在创建表类型之前必须知道列名。



我的要求是将随机列传递给SP。是否可以将其列始终随机的DataTable传递给存储过程。



任何帮助或建议...



我尝试过:



在google&上搜索很多尝试了http://www.aspsnippets.com/Articles/Send-PassANNTable-as-parameter-to-Stored-Procedure-in-C-and-VBNet.aspx,http://cn.cjectproject.com/文章/ 412802 /发送数据表到存储过程等等

The most efficient way for Passing DataTable to Stored Procedure is by using User Defined Table Type. But it requires that column names must be known prior to creating table type.

My requirement is to pass random columns to SP. Is it possible to pass DataTable whose columns are always random to Stored procedure.

Any help or suggestion...

What I have tried:

Searching a lot on google & tried with http://www.aspsnippets.com/Articles/Send-Pass-DataTable-as-parameter-to-Stored-Procedure-in-C-and-VBNet.aspx , http://www.codeproject.com/Articles/412802/Sending-a-DataTable-to-a-Stored-Procedure etc etc

推荐答案

嗯,是的 - 确实如此。但这是有充分理由的。

需要列名,因为它们是存储过程在到达时用于访问表数据的内容 - 如果没有指定列名,则SQL表无法创建,如果是,则SP无法访问它们。 SQL不适用于列索引,除非有一些非常讨厌的摆弄。



所以给列通用名称 - C1,C2, ......并且两端都能正常工作。
Well, yes - it does. But that's for a good reason.
Column names are needed because they are what the stored procedure uses to access the Table data once it arrives - and if you don't specify the column names, the SQL Table can't be created, and the SP couldn't access them if it was. SQL will not work with "column indexes" except by some very nasty fiddling around.

So give the columns "generic names" - "C1", "C2", ... and both ends will work fine.


这篇关于将带有随机列的数据表传递给存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆