I am displaying categories in a dropdown list for adding products. When a product is to be added, you will have to select a category and Create Product or Update a previous product.
But my problem is that I get the following error:
No mapping exists from object type
System.Web.UI.WebControls.DropDownList to a known managed provider
native type.
Database Diagram:

ASPX.:
<p>Kategori</p>
<asp:DropDownList ID="DDCategories" runat="server" AutoPostBack="True">
</asp:DropDownList>
ASPX.CS.:
protected void Page_Load(object sender, EventArgs e)
{
//Dropdown Category Names From DB
if (!IsPostBack)
{
string sConstr = ConfigurationManager.ConnectionStrings["LLcateringConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(sConstr);
DataTable dt = new DataTable("tbl");
using (Conn)
{
Conn.Open();
SqlCommand comm = new SqlCommand("SELECT Name FROM Category", Conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
da.Fill(dt);
}
DDCategories.DataSource = dt;
DDCategories.DataTextField = "Name";
DDCategories.DataBind();
}
}
protected void BtnUpdateOrCreate_Click(object sender, EventArgs e)
{
// Text in fields has to exist, if they are requierd
if (!string.IsNullOrWhiteSpace(TxtName.Text) /*&&
!string.IsNullOrWhiteSpace(TxtDescription.Text)*/)
{
// New the DataAccess and have all the parameteres here
DataAccess dataAccess = new DataAccess();
dataAccess.AddParameter("@Name", TxtName.Text);
dataAccess.AddParameter("@Category_ID", DDCategories);
dataAccess.AddParameter("@Description", TxtDescription.Text.ToNewline(false));
dataAccess.AddParameter("@UnitPrice", TxtPrice.Text);
dataAccess.AddParameter("@DiscountUnitPrice", TxtUnitDiscount.Text);
if (isCreate)
{
// Insert query
dataAccess.Execute(@"INSERT INTO [Product] ([Name], [Category_ID], [UnitPrice], [DiscountUnitPrice], [Description])
VALUES (@Name, @Category_ID, @UnitPrice, @DiscountUnitPrice, @Description)
INNER JOIN dbo.Product ON dbo.Category.ID = dbo.Product.Category_ID
ORDER BY [Name]
WHERE id = @id");
}
else
{
// Update query
dataAccess.AddParameter("@id", MenuID);
dataAccess.Execute(@"UPDATE [Product]
SET [Name] = @Name, [Category_ID] = @Category_ID, [UnitPrice] = @UnitPrice, [DiscountUnitPrice] = @DiscountUnitPrice, [Description] = @Description
WHERE id = @id");
//UPDATE [Product]
//SET [Name] = @Name, [Category_ID] = @Category_ID, [UnitPrice] = @UnitPrice, [DiscountUnitPrice] = @DiscountUnitPrice, [Description] = @Description
//INNER JOIN dbo.Product ON dbo.Category.ID = dbo.Product.Category_ID
//ORDER BY [Name]
//WHERE id = @id");
}
// Redirects to list
Response.Redirect(Request.Url.AbsolutePath);
}
else
LitStatus.Text = "Hey så indtast da noget!";
}
check this line
dataAccess.AddParameter("@Category_ID", DDCategories);and replace with
dataAccess.AddParameter("@Category_ID", DDCategories.SelectedValue)