locked
why's the error not found namespace or class ? RRS feed

  • Question

  • User-663551687 posted

    You see the example below why the error not found namespace or class ?

    http://www.mediafire.com/file/iiak7w5nhhab3ju/Namespace_asp_net.rar/file

    Monday, April 8, 2019 4:58 AM

All replies

  • User283571144 posted

    Hi dongtrien,

    The code you have upload doesn't have the namespace in the aspx file. This is the reason.

    If you want to solve this issue, I suggest you could create a new web application, create a new page,clsConnecSQL class file, then you could copy all the codes in it.

    Best Regards,

    Brando

    Monday, April 8, 2019 6:27 AM
  • User-663551687 posted

    Can my example be posted irreparably ? I created a new web application that still has this error, can you just help me fix the above error ? I do not understand

    Monday, April 8, 2019 7:09 AM
  • User283571144 posted

    Hi dongtrien,

    Could you please tell me which class you faced not found namespace or class error?

    I suggest you could click the show potential fixes to add the right namespace.

    Like below:

    Best Regards,

    Brando

    Tuesday, April 9, 2019 5:11 AM
  • User-663551687 posted

    If you look at my example sent this website, you can fix it, I don't know how to fix my example error

    Tuesday, April 9, 2019 9:36 AM
  • User283571144 posted

    Hi dongtrien,

    If you look at my example sent this website, you can fix it, I don't know how to fix my example error

    You could refer to below codes:

    You should replace the namespace to  your own namespace

    ASPX PAGE:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestNameSpace.aspx.cs" Inherits="WebFormForComplieTest.TestNameSpace" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
            <asp:Label ID="lblName" runat="server" Text="Tìm kiếm:"></asp:Label>
            <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
            <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
            <asp:Label ID="lblMessage" runat="server"></asp:Label>
            <br />
            <br />
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>   
            </div>
        </form>
    </body>
    </html>
    

    Code-behind:

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebFormForComplieTest
    {
        public partial class TestNameSpace : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    LoadData();
                }
            }
    
            string sSQL;
            private void LoadData()
            {
    
    
                sSQL = "SELECT NGAY, MASOPHIEU, KHACHDUA, TONGTIEN, TONGTHU, TENKH, TEL, ADRESS, GIAM, DOITRA, TTTHANHTOAN, THANHTOAN, MANHANVIEN, NHANVIEN ";
                sSQL += "FROM TABKHACHHANGNOCTTMP ";
                sSQL += "ORDER BY MASOPHIEU;";
                Debug.Print("sSQL: " + sSQL.ToString());
                //DataTable dtKhachNoTmp = clsConnecACS.FillDatatable(sSQL);
                //ClsConnecSQL abc = new ClsConnecSQL();
                //GridView1.DataSource = abc.FillDatatable(sSQL);
                GridView1.DataSource = clsConnecSQL.FillDatatable(sSQL);
            }
    
            private void LoadData(string tenNhanVien)
            {
                sSQL = "SELECT NGAY, MASOPHIEU, KHACHDUA, TONGTIEN, TONGTHU, TENKH, TEL, ADRESS, GIAM, DOITRA, TTTHANHTOAN, THANHTOAN, MANHANVIEN, NHANVIEN ";
                sSQL += "FROM TABKHACHHANGNOCTTMP ";
                sSQL += "WHERE TABKHACHHANGNOCTTMP.TEN = N'" + tenNhanVien + "' ";
                sSQL += "ORDER BY MASOPHIEU;";
                Debug.Print("sSQL: " + sSQL.ToString());
    
                GridView1.DataSource = clsConnecSQL.FillDatatable(sSQL);
            }
    
            protected void btnSearch_Click(object sender, System.EventArgs e)
            {
                if (string.IsNullOrEmpty(txtSearch.Text))
                {
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    lblMessage.Text = "Nhập [Tên nhân viên] cần tìm";
                }
                else
                {
                    lblMessage.Text = "";
                    LoadData(txtSearch.Text.Trim());
                }
            }
        }
    }

    clsConnecSQL.cs:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Drawing;        
    using System.Diagnostics;    
    using System.Data.SqlClient; 
    using System.Windows.Forms;  
    using System.Configuration;  
    
    using connectSQL;
    
    namespace connectSQL //System.Web.UI.Page //
    {
        public class ClsConnecSQL
        {
    
            public static DataTable FillDatatable(string sSQL)
            {
                SqlConnection sqlConn = new SqlConnection(connectionString);
                sqlConn.Open();
                DataTable dataTable = new DataTable();
                SqlDataAdapter adapter = new SqlDataAdapter(sSQL, sqlConn);
                adapter.Fill(dataTable);
    
                return dataTable;
            }
    
            public static DataTable Plus(int a, int b)
            {
                return a + b;
            }
    
    
    
        }   
    }
    
            

    Best Regards,

    Brando

    Wednesday, April 10, 2019 8:36 AM
  • User-663551687 posted

    I check your code and fix it

    In ChitietSP.aspx
    My code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChitietSP.aspx.cs" Inherits="_Default" %> Your code: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestNameSpace.aspx.cs" Inherits="WebFormForComplieTest.TestNameSpace" %>

    In ChitietSP.aspx.cs
    My code:
    I'm not namespace WebFormForComplieTest

    Your code:
    namespace WebFormForComplieTest
    {
    public partial class TestNameSpace : System.Web.UI.Page
    {
    // code ...
    }
    // code ...
    }

    but still can't run, if your fix is reported the following error: 

    Error 1: Could not load type 'WebFormForComplieTest.TestNameSpace'. x:\...\ChitietSP.aspx 1

    Error 2: Warning 2 Attribute 'Codebehind' in the @ Page directive is no longer supported. Convert this page to the new code-behind model by opening the Web site (project) containing the page in Visual Web Developer. x:\Namespace_asp_net\ChitietSP.aspx 1 47 x:\Namespace_asp_net\

    Thursday, April 11, 2019 9:14 AM
  • User283571144 posted

    Hi dongtrien,

    dongtrien

    Error 1: Could not load type 'WebFormForComplieTest.TestNameSpace'. x:\...\ChitietSP.aspx 1

    Yes, this is my test web application namespace, you should modify it to your current web application's namespace.

    dongtrien

    Error 2: Warning 2 Attribute 'Codebehind' in the @ Page directive is no longer supported. Convert this page to the new code-behind model by opening the Web site (project) containing the page in Visual Web Developer. x:\Namespace_asp_net\ChitietSP.aspx 1 47 x:\Namespace_asp_net\

    You should create a new web form page and copy my aspx page's body codes to the your web form page, then it will work well.

    Best Regards,

    Brando

    Wednesday, April 17, 2019 1:48 AM
  • User-663551687 posted

    Can you repaid and upload it from my original example ? I see the code you fix there are 2 places I mentioned above but it's appears more errors

    Wednesday, April 17, 2019 4:29 AM
  • User283571144 posted

    Hi dongtrien,

    I have copy the whole codes and it works well on my side.

    I think should firstly understand how to reference the library in C#. 

    I suggest you could refer to below article to know C# base.

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/index 

    Best Regards,

    Brando

    Monday, April 22, 2019 9:11 AM
  • User-663551687 posted

    C# theory I read a lot already, in the winform I declare the library as above is a good run but in webform I declare as above then report an error, can you briefly say I can understand why the above error ?

    Wednesday, April 24, 2019 2:36 AM
  • User-663551687 posted

    Does anyone know to fix this?

    Friday, May 10, 2019 4:27 AM
  • User283571144 posted

    Hi dongtrien,

    As my pervious reply says, since we don't knwo details information and codes about your current web application, we couldn't reproduce your issue.

    All the codes is work well on my side.

    If possible, please tell me your Email address in private message. I will share a Microsoft share link with you, you could upload the whole web application for me to test it.

    Thank you.

    Best Regards,

    Brando

    Wednesday, May 15, 2019 2:46 AM
  • User-663551687 posted

    I have got sent my code error example attachment above but no one has seen my code, now I have found the cause of the error, because I did not put the class file (clsConnecSQL.cs) inside "App_Code" directory should asp.net not understand GridView1.DataSource = clsConnecSQL.FillDatatable derived class (sSQL); // this error is now out of error, and I'm not need fix "CodeFile" converted into "CodeBehind", I still get "CodeFile" run fine, I learned asp.net myself, so I really know you only help, thank you for reading my article.

    Tuesday, May 21, 2019 3:33 AM