0

this is a Class in my code:

public class Pr
{

    public Pr()
    {
        //Blank Instructor
    }


    public void AddP(string code, string name, double price)
    {
        string str = "Select * From products Where pcode='" + code + "';";
        string dbName = "DataBaseS.mdb";
        DataTable dt = new DataTable();
        dt = Dbase.SelectFromTable(str, dbName);
        if (dt.Rows.Count == 0)
        {
            string strSql = "INSERT INTO [products] ([pcode] , [pname] , [pprice]) VALUES ('" + code 
+ "','" + name + "','" + "','" + price + "');";
            int didItWork = Dbase.ChangeTable(strSql, dbName);

        }
    }


    public void DeleteP(string code)
    {
        string str = "Select * From products Where pcode='" + code + "';";
        string dbName = "DataBaseS.mdb";
        DataTable dt = new DataTable();
        dt = Dbase.SelectFromTable(str, dbName);
        if (dt.Rows.Count == 0)
        {
            string strSql = "DELETE * From [products] WHERE pcode='" + code + "');";
            int didItWork = Dbase.ChangeTable(strSql, dbName);
        }

    }

    public void UpdatePPrice(string code, double price)
    {
        string str = "Select * From products Where pcode='" + code + "';";
        string dbName = "DataBaseS.mdb";
        DataTable dt = new DataTable();
        dt = Dbase.SelectFromTable(str, dbName);
        if (dt.Rows.Count == 0)
        {
            string strSql = "UPDATE [products] SET pprice='" + price + "' WHERE pcode='" + code + 
"');";
            int didItWork = Dbase.ChangeTable(strSql, dbName);
        }
    }

}

This Class is used in a webform with master page as following:

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

namespace WebProject.Site1
{
public partial class UpdateProducts : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Pr pr = new Pr();

        if (addcheck.Checked)
        {
            double pprice = double.Parse(addproductprice.Text);
            pr.AddP(addproductcode.Text, addproductname.Text, pprice);
            changedone.Text = "product added";
            changedone.Visible = true;
        }
        if (deletecheck.Checked)
        {
            pr.DeleteP(addproductcode.Text);
            changedone.Text = "product deleted";
            changedone.Visible = true;
        }
        if (addcheck.Checked)
        {
            double cpprice = double.Parse(changeproductprice.Text);
            pr.ChangePPrice(addproductcode.Text, cpprice);
            changedone.Text = "price changed";
            changedone.Visible = true;
        }
    }
}
}

A red line is shown under the command "Pr pr = new Pr();" and it says :"The type or namespace name 'Pr' could not be found (are you missing a using directive or an assembly refrence?)"

What is wrong with the code? I mean the red line is only under the command where I define a new Pr but it isn't shown under cmmands like "pr.DeleteP(addproductcode.Text);".

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Seat Geek
  • 3
  • 1
  • 2
    To which namespace does `Pr` belong to? If it´s not `namespace WebProject.Site1` you have to add a `using` on top of your `UpdateProject`-coursecode-file. – MakePeaceGreatAgain Oct 20 '19 at 18:28
  • But you don't need a namespace in the web form's code-behind. Try removing that. – wazz Oct 20 '19 at 20:23
  • Possible duplicate of [The type or namespace name 'XmlDocument' could not be found. Are you missing an assembly reference?](https://stackoverflow.com/questions/31494879/the-type-or-namespace-name-xmldocument-could-not-be-found-are-you-missing-an) – Jamshaid K. Oct 20 '19 at 23:52

0 Answers0