Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.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# 如何从数据集中读取int值?在C中_C#_Sql_Dataset - Fatal编程技术网

C# 如何从数据集中读取int值?在C中

C# 如何从数据集中读取int值?在C中,c#,sql,dataset,C#,Sql,Dataset,如果我有一个返回DataSet的函数,它有一行int值 如何读取该int值?为什么要将数据集用于单个静态值。如果您使用的是sql reader,请使用ExecuteScalar函数 例如: function GetIntValue() { SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["con"]); con.Open(); SqlCommand cmdCount = new S

如果我有一个返回DataSet的函数,它有一行int值


如何读取该int值?

为什么要将数据集用于单个静态值。如果您使用的是sql reader,请使用ExecuteScalar函数

例如:

function GetIntValue()
{
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["con"]);

    con.Open();

    SqlCommand cmdCount = new SqlCommand("SELECT COUNT(*) FROM Employees",con);
    int numberOfEmployees = (int)cmdCount.ExecuteScalar();
    Response.Write("Here are the " + numberOfEmployees.ToString() + " employees: <br><br>");

    SqlCommand cmd = new SqlCommand("SELECT * FROM Employees",con);
    SqlDataReader dr = cmd.ExecuteReader();
    while(dr.Read()) {
        Response.Write(dr["LastName"] + "<br>");
    }
    con.Close();
}

对不起,我不明白答案。我做了一个函数,返回一行,其中有一个值,我想做一些事情,比如textbox1.text=function.getdata我怎么做?请参考这个例子@user2120874,而不是将函数读入数据集,使用上面提到的ExecuteScalar将函数结果直接读入变量。非常好,谢谢