The type or namespace name 'Product' could not be found (are you missing a using directive o

Posted by maninaanee-8287 under ASP.NET on 12/12/2011 | Points: 10 | Views : 1324 | Status : [Member] | Replies : 1
In my dal -------------error is occured.
namespace pnGridDal
{
public class pnGrdDal
{
public static List<Product> GetProducts()
{
return GetProducts(int.MaxValue, 0);
}
//public static List<Product> GetProducts(int maximumRows,
// int startRowIndex)
//{
// return GetProducts(maximumRows, startRowIndex);
//}
public static List<Product> GetProducts(int maximumRows,
int startRowIndex)
{
// returns a list of Product instances based on the
// data in the Northwind Products table
string sql = @"SELECT ProductID, ProductName, QuantityPerUnit,
UnitPrice, UnitsInStock
FROM Products";
using (SqlConnection myConnection = new
SqlConnection(ConfigurationManager.ConnectionStrings[
"NWConnectionString"].ConnectionString))
{
// Place the data in a DataTable
SqlCommand myCommand = new SqlCommand(sql, myConnection);
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
myConnection.Open();
DataTable dt = new DataTable();
myAdapter.Fill(dt);
List<Product> results = new List<Product>();
int currentIndex = startRowIndex;
int itemsRead = 0;
int totalRecords = dt.Rows.Count;
while (itemsRead < maximumRows &&
currentIndex < totalRecords)
{
Product product = new Product();
product.ProductID =
Convert.ToInt32(dt.Rows[currentIndex]["ProductID"]);
product.ProductName =
dt.Rows[currentIndex]["ProductName"].ToString();
product.QuantityPerUnit =
dt.Rows[currentIndex]["QuantityPerUnit"].ToString();
if (dt.Rows[currentIndex]
["UnitPrice"].Equals(DBNull.Value))
product.UnitPrice = 0;
else
product.UnitPrice =
Convert.ToDecimal(dt.Rows[currentIndex]["UnitPrice"]);
if (dt.Rows[currentIndex]
["UnitsInStock"].Equals(DBNull.Value))
product.UnitsInStock = 0;
else
product.UnitsInStock =
Convert.ToInt32(dt.Rows[currentIndex]["UnitsInStock"]);
results.Add(product);
itemsRead++;
currentIndex++;
}
myConnection.Close();
return results;
}
}
}
}




Responses

Posted by: Sksingh on: 12/12/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Check where did u create a entity "Product" and what is namespace for it .
If there are also same namespace as pnGridDal then no need to put namespace explicitly otherwise include that namespace.

Hope it will work..

Regards,
Sunil

maninaanee-8287, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response