0

私は .net の新しい開発者です。接続ヘルパー クラスを作成しました。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public static class DBConnectionHelper
{
    public static SqlConnection GetConnection()
    {
        return new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ToString());
    }
}

以下を使用して cs ファイルを呼び出します。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBConnectionHelper;



public partial class administration_login : System.Web.UI.Page
{


    protected void Page_Load(object sender, EventArgs e)
    {

        //var DBConnectionHelper= new DBConnectionHelper();

        using (var cn = DBConnectionHelper.GetConnection())
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM users", cn);
            cn.Open();
            SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            while (rdr.Read())
            {
               Response.Write( rdr["first_name"].ToString()+ "<br>");
               // Response.Write(rdr[1].ToString()+"<br>"); //read a value
            }
        }
    }

}

エラーが発生する理由: エラー 32 The type or namespace name 'ConnectionHelper' could not be found (using ディレクティブまたはアセンブリ参照がありませんか?)

ここに画像の説明を入力

私を助けてください。

4

2 に答える 2