-5

DataSet を返す関数がある場合、 int value を持つ1行があります。

そのint値をどのように読み取ることができますか?

4

1 に答える 1

6

単一の静的値にデータセットを使用する理由。SQLリーダーを使用している場合は、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();
}
于 2013-03-01T17:53:01.247 に答える