如何使用存储过程在c#中的Mysql数据读取器中返回单行 [英] how to return a single row in Mysql data reader in c# using stored procedure

查看:57
本文介绍了如何使用存储过程在c#中的Mysql数据读取器中返回单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,
我想从mysql数据库表中检索符合条件的一行.我有一个存储过程.
例如.从user_table中获取使用用户名进行搜索的特定用户的所有列
请帮帮我.

在此先感谢您.

Dear Friends,
I want to retrieve a single row from mysql database table,which match the condition. i have a stored procedure.
Eg. get all columns from user_table for a particular user that is search with username
Please help me.

Thanks in Advance.

推荐答案

使您存储的proc返回您想要的内容,不要处理代码中的内容.您的函数可以返回您想要的任何东西.实际上,您的问题没有任何意义.为什么不能返回一行?
Make your stored proc return what you want it to, don''t process stuff in code. Your function can return anything you want. In fact, your question makes no sense. Why CAN''T you return a single row ?


如果您想将MySqlDataReader强制转换为DataRow,我认为这是不可能的.但是,您可能希望根据情况将数据读取器的值放入数组或集合中.希望本示例对您有帮助

If you mean you want to cast a MySqlDataReader to a DataRow, I dont think this is possible. You may, however, want to put the values of the data reader to an array or a collection, depends on your situation. Hope this example helps

while (reader.Read())
{
   if (reader["user_name"] == "SoAndSo")
   {
      for(int i = 0; i < reader.FieldCount; i++)
      {
         myArray[i] = reader[i]; //I only used array as an example but you may use built in collections.
      }
      break;
   }
}


这篇关于如何使用存储过程在c#中的Mysql数据读取器中返回单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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