Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在mysql中创建读取函数_C#_Asp.net_Mysql_Database - Fatal编程技术网

C# 如何在mysql中创建读取函数

C# 如何在mysql中创建读取函数,c#,asp.net,mysql,database,C#,Asp.net,Mysql,Database,我不熟悉asp.net和c。我如何设计一个读取函数?在单词read下面有一条红线 下面的代码是我现在的代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Text; using MySql.Data; using MySql.Data.MySqlClient; using System.Data; using System.Configuratio

我不熟悉asp.net和c。我如何设计一个读取函数?在单词read下面有一条红线

下面的代码是我现在的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;



namespace P1
{
    public class EPSData
    {
        private MySqlConnection con = null;
        private MySqlCommand cmd = null;
        private MySqlDataReader rdr;
        //DataSet ds = new DataSet(cmd,con); //
        //private MySqlDataAdapter da = new MySqlDataAdapter();
        //private DataSet ds = new DataSet();

        public string read()
        {
            con = new MySqlConnection("Server=localhost;Database=staff;Uid=root;Pwd=password");

            con.Open();

            string cmdStr = "SELECT * FROM approver WHERE ID = 'ApproverID';";


            cmd = new MySqlCommand();
            cmd.CommandText = cmdStr;
            cmd.Connection = con;


            con.Close();

        }


    }

}
read()方法没有任何返回语句

您声明了一个由read方法返回的字符串值,因此必须执行以下操作

return "Some String value";

有关MysqlCommand类和用法的一些信息。你可以在网上找到很多信息

您的方法
publicstringread()
确定当您不从方法体返回
string
时,它将返回
string
。将方法返回类型声明为
void
或添加
return“some str”
作为
方法主体中的
最后一行

,您需要实际检索要返回的数据,然后使用return语句返回该数据


放入
返回read()最后将无法解决您的问题。这只会导致该方法重新调用自身,直到内存耗尽或堆栈溢出。

因此,我将只放置return read();在con.Close()的底部?例如,如果我希望它返回approverID,我将返回approverID()?我建议您阅读更多关于ADO.net和数据检索过程的信息。。您必须使用MySQLDataReader来获取和操作数据,因此我将只放置return read();在con.Close()的底部?例如,如果我希望它返回approverID,我将返回approverID()?在最后一行中,您可以返回“ApproverID”;
read()
应该返回什么?另外,.Net编程约定要求方法名称以大写字母开头,也称为Pascal大小写。