商品を追加するためのドロップダウンリストにカテゴリを表示しています。製品を追加する場合は、カテゴリを選択して製品を作成するか、以前の製品を更新する必要があります。DropDownListでのマッピングエラー
しかし、私の問題は、私は次のエラーを取得ことです:
No mapping exists from object type System.Web.UI.WebControls.DropDownList to a known managed provider native type.
データベースダイアグラム:
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!";
}
を
と交換してください? Response.Redirect(Request.Url.AbsolutePath); – Lloyd
@Lloydは、すべての製品がリストされたページにリダイレクトされます。しかし、「更新」または「作成」をクリックしたときに上に表示されるエラーのために、動作しているかどうかはわかりません。 –
同じページにリダイレクトしていますか? – Lloyd