我在SQL Server中有存储过程并将其转换为实体模型中的函数,现在如何将我的函数的输出转换为C#中的给定类型int,string
等等?如何将存储过程结果转换为特定类型
实施例:
Testentities test=new TestEntities();
object d=test.FunctionTest("Params");
我在SQL Server中有存储过程并将其转换为实体模型中的函数,现在如何将我的函数的输出转换为C#中的给定类型int,string
等等?如何将存储过程结果转换为特定类型
实施例:
Testentities test=new TestEntities();
object d=test.FunctionTest("Params");
要的字符串:
Testentities test = new TestEntities();
object d = test.FunctionTest("Params");
string result = d.ToString();
为INT:
Testentities test = new TestEntities();
object d = test.FunctionTest("Params");
int result = Convert.ToInt32(d);
在.NET Convert
类可以转化成许多不同的类型。
不过提醒一句:当然你需要一定的目标类型是正确的类型,即使这样的- 你需要的事实转换可能会失败有所准备 - 把这个在try...catch
块!
更新:你已经显露之后的结果,其实是List<object>
,你需要做的是这样的:
Testentities test = new TestEntities();
object d = test.FunctionTest("Params");
List<string> results = new List<string>();
foreach(object o in d)
{
results.Add(o.ToString());
}
,并同样可以与int
值来实现(只是用Convert.ToInt32()
在foreach
循环
FunctionTest是一个列表
只是给所有想回答的人的一个提示:OP在他的问题中提到** NOT **,结果是'List
@marc_s,什么是地狱?谷歌称这是“手术或其他手术,军事行动”。 – usefulBee
@usefulBee:** O ** riginal ** P ** oster - 发布该问题的SO成员.... –