我从这段代码中返回了什么? [英] What I return from this code?

查看:60
本文介绍了我从这段代码中返回了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

get_email_id_user_rolewise是我的存储过程,它只从我的数据库表中返回单个列中的11个emailid的列表,所以我想知道我是否在下面的代码中编写,然后我在这段代码的最后一行的电子邮件字符串中返回了什么? br $>


 command.CommandText =   get_email_id_user_rolewise; 
command.Parameters.AddWithValue( @ circle,circle);
reader = command.ExecuteReader();
string email = ;
while (reader.Read())
{
email = reader [ 0 ]的ToString();
}
返回电子邮件;





我的尝试:



i已尝试上面的代码,但无法获得结果,因为我的移动应用程序当前无法正常工作。

解决方案

您将返回最后一项。

创建一个电子邮件数组然后返回数组然后你可以在单列中使用for循环打印出来


如果你想要返回所有电子邮件,试试这个:



 StringBuilder sb =  new  StringBuilder(); 
while (reader.Read())
{
sb.Append(reader [ 0 ]。ToString()+ ;);
}
return sb.ToString();





以上代码应返回由; ,例如: JohnDoe@g.com; JaneDoe@h.com; ...; AliBabaAnd40Robbers@z.com



详情请见: StringBuilder类(System.Text) [ ^ ]


"get_email_id_user_rolewise" is my stored procedure, it returns 11 emailid's list in single column only from my database table, so i want to know if i write below code then what i return in email string at last line of this code?

command.CommandText = "get_email_id_user_rolewise";
command.Parameters.AddWithValue("@circle", circle);
reader = command.ExecuteReader();
string email = "";
while (reader.Read())
{
     email = reader[0].ToString();
}
return email;



What I have tried:

i have tried above code but cant get result, because my mobile application is not working currently.

解决方案

You are returning the last item.


create an array of email then return the array and then you can print it out using for loop in single column


If you would like to return all emails, try this:

StringBuilder sb = new StringBuilder();
while (reader.Read())
{
     sb.Append(reader[0].ToString() + "; ");
}
return sb.ToString();



Above code should return a list of emials separated by ";", for example: "JohnDoe@g.com; JaneDoe@h.com; ...; AliBabaAnd40Robbers@z.com"

For further details, please see: StringBuilder Class (System.Text)[^]


这篇关于我从这段代码中返回了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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