473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help with Dropdownlist using forgeign key table

Hi Guys, this is kinda complicated but ill do my best to explain.
I have two tables. products and categories. Products holds product info and an image, its primary key is ProductID. Category table holds a category name and description and a primary key CategoryID. The producs table holds a Foreign key field called CategoryID which points to the CategoryID Primary key of the catgory table.

Ok i have two asp.net 2 vb forms. One is using a detailsview to edit, insert and update Category. I did this so that the end user could add new categories and descriptions to the Categories of products. This works fine.

My second page/ from is the product updates page, it works fine uploads the image, inserts the product info fine however i had to add in a dropdownlist where i wanted the user to select the category. Obviosly i couldnt use the category ID for the text as no one would know which id meant what, so i chose the Category Name as the datatext and Used the category ID as the datavalue and i bound the selected value to CategoryID. I Keep getting an error message when i submit saying "MUST DECLARE SCALAR VARIABLE @dropdownlist1" in new to all this and stuck, can someone take a look and advise me how to fix this.

My code is attached

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2.  
  3. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
  4.     <asp:DetailsView ID="UploadProductsImageUI" runat="server" DataSourceID="UploadPictureDataSource" DataKeyNames="ProductID" AutoGenerateRows="False" DefaultMode="Insert">
  5.         <Fields>
  6.             <asp:TemplateField HeaderText="Product Name">
  7.                 <InsertItemTemplate>
  8.                     <asp:TextBox ID="ProductName" runat="server" Text='<%# Bind("ProductName") %>'></asp:TextBox>
  9.                 </InsertItemTemplate>
  10.             </asp:TemplateField>
  11.             <asp:TemplateField HeaderText="Category">
  12.                 <InsertItemTemplate>
  13.                     <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="category" DataTextField="CategoryName"
  14.                         DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
  15.                     </asp:DropDownList>
  16.                 </InsertItemTemplate>
  17.             </asp:TemplateField>
  18.             <asp:TemplateField HeaderText="Colour">
  19.                 <InsertItemTemplate>
  20.                     <asp:ListBox ID="Colour" runat="server" CssClass="content" Enabled="true" SelectionMode="Single">
  21.                         <asp:ListItem>- Please Select -</asp:ListItem>
  22.                         <asp:ListItem>Autumn Brown</asp:ListItem>
  23.                         <asp:ListItem>Black</asp:ListItem>
  24.                         <asp:ListItem>Fossil Mint</asp:ListItem>
  25.                         <asp:ListItem>Kotah Black</asp:ListItem>
  26.                         <asp:ListItem>kotah Blue</asp:ListItem>
  27.                         <asp:ListItem>Misty Grey</asp:ListItem>
  28.                         <asp:ListItem>Peacock</asp:ListItem>
  29.                         <asp:ListItem>Raj Green</asp:ListItem>
  30.                     </asp:ListBox><br />
  31.                 </InsertItemTemplate>
  32.             </asp:TemplateField>
  33.             <asp:TemplateField HeaderText="Product Price Landscaper">
  34.                 <InsertItemTemplate>
  35.                     <asp:TextBox ID="ProductPriceLandscaper" runat="server" Text='<%# Bind("ProductPriceLandscaper") %>'></asp:TextBox>
  36.                 </InsertItemTemplate>
  37.             </asp:TemplateField>
  38.             <asp:TemplateField HeaderText="Product Price Retail">
  39.                 <InsertItemTemplate>
  40.                     <asp:TextBox ID="ProductPriceRetail" runat="server" Text='<%# Bind("ProductPriceRetail") %>'></asp:TextBox>
  41.                 </InsertItemTemplate>
  42.             </asp:TemplateField>
  43.             <asp:TemplateField HeaderText="Product Price Wholsale">
  44.                 <InsertItemTemplate>
  45.                     <asp:TextBox ID="ProductPriceWholeSale" runat="server" Text='<%# Bind("ProductPriceWholeSale") %>'></asp:TextBox>
  46.                 </InsertItemTemplate>
  47.             </asp:TemplateField>
  48.             <asp:TemplateField HeaderText="Product Image">
  49.                 <InsertItemTemplate>
  50.                     <asp:FileUpload ID="UploadedFile" runat="server" />
  51.                 </InsertItemTemplate>
  52.             </asp:TemplateField>
  53.             <asp:TemplateField HeaderText="Image Title">
  54.                 <InsertItemTemplate>
  55.                     <asp:TextBox ID="ImageTitle" runat="server" Text='<%# Bind("ImageTitle") %>'></asp:TextBox>
  56.                 </InsertItemTemplate>
  57.             </asp:TemplateField>
  58.             <asp:TemplateField HeaderText="Size">
  59.                 <InsertItemTemplate>
  60.                     <asp:TextBox ID="Size" runat="server" Text='<%# Bind("Size") %>'></asp:TextBox>
  61.                 </InsertItemTemplate>
  62.             </asp:TemplateField>
  63.             <asp:TemplateField HeaderText="Pcs Crate">
  64.                 <InsertItemTemplate>
  65.                     <asp:TextBox ID="pcsCrate" runat="server" Text='<%# Bind("PcsCrate") %>'></asp:TextBox>
  66.                 </InsertItemTemplate>
  67.             </asp:TemplateField>
  68.             <asp:TemplateField HeaderText="Sgm Crate">
  69.                 <InsertItemTemplate>
  70.                     <asp:TextBox ID="sgmCrate" runat="server" Text='<%# Bind("SgmCrate") %>'></asp:TextBox>
  71.                 </InsertItemTemplate>
  72.             </asp:TemplateField>
  73.             <asp:TemplateField HeaderText="Weight">
  74.                 <InsertItemTemplate>
  75.                     <asp:TextBox ID="weight" runat="server" Text='<%# Bind("Weight") %>'></asp:TextBox>
  76.                 </InsertItemTemplate>
  77.             </asp:TemplateField>
  78.             <asp:TemplateField ShowHeader="False">
  79.                 <InsertItemTemplate>
  80.                     <asp:LinkButton ID="btnInsert" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" ForeColor="#000099"></asp:LinkButton><br />
  81.                     <asp:LinkButton ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" OnClick="btnCancel_Click" ForeColor="#000099"></asp:LinkButton>
  82.                 </InsertItemTemplate>
  83.             </asp:TemplateField>
  84.         </Fields>
  85.     </asp:DetailsView>
  86.     &nbsp;
  87.     <asp:SqlDataSource ID="category" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringAccountType %>"
  88.         SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Category]"></asp:SqlDataSource>
  89.     <br />
  90.      <asp:SqlDataSource ID="UploadPictureDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringAccountType %>"
  91.         InsertCommand="INSERT INTO [Products]([ProductName], [CategoryID], [Colour], [ProductPriceRetail], [ProductPriceWholeSale], [ProductPriceLandscaper], [ImageTitle], [ImageData], [ImageMimeType], [Size], [PcsCrate], [SgmCrate], [Weight]) VALUES (@ProductName, @DropDownList1, @Colour, @ProductPriceRetail, @ProductPriceWholeSale, @ProductPriceLandscaper, @ImageTitle, @ImageData, @MimeType, @Size, @pcsCrate, @sgmCrate, @weight)">
  92.         <InsertParameters>
  93.         <asp:Parameter Name="ProductName" Type="string" />
  94.         <asp:Parameter Name="CategoryID" Type="int32" />
  95.         <asp:Parameter Name="Colour" Type="string" />
  96.         <asp:Parameter Name="ProductPriceRetail" Type="string" />
  97.         <asp:Parameter Name="ProductPriceWholeSale" Type="String" />
  98.         <asp:Parameter Name="ProductPriceLandscaper" Type="string" />
  99.         <asp:Parameter Name="ImageTitle" Type="string" />
  100.         <asp:Parameter Name="ImageData" />
  101.         <asp:Parameter Name="MimeType" Type="string" />
  102.         <asp:Parameter Name="Size" Type="string" />
  103.         <asp:Parameter Name="pcsCrate" Type="string" />
  104.         <asp:Parameter Name="sgmCrate" Type="string" />
  105.         <asp:Parameter Name="weight" Type="string" /> 
  106.         </InsertParameters>
  107.         </asp:SqlDataSource>
  108.         <asp:Label ID="ErrorMessage" runat="server" EnableViewState="False" Visible="False"></asp:Label>
  109. </asp:Content>
May 5 '07 #1
2 1773
kenobewan
4,871 Expert 4TB
I suggest try debugging without dropdownlist first. If this works why isn't it recognising the name?
May 5 '07 #2
I suggest try debugging without dropdownlist first. If this works why isn't it recognising the name?
If i dont have the drop down it works fine and writes the info to my db products table.

This problem only started happening when i added in the drop list, ive read up briefly on dropdown lists and something about the selected value, do i need to have a function for this so that when they select this it captures the selection?
May 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
6
by: Teep | last post by:
Below is my code for dropdownlist that is populated from a SQL table. After a selection from the ddl, a datagrid is suppose to come up pertaining to the information selected, but I keep getting a...
0
by: Aws | last post by:
My crazy GridView !! I am using Visual Studio 2005, I have a problem with my GridView. I have one access .mdb table and when I update a record on the table EVERYTHING is perfect. I made a Web...
2
by: Sam | last post by:
A) Destination Table with 4 Fields. 1) Last Name 2) First Name 3) State 4) Zip Code. B) Look up table State/Zip Code with 2 Fields
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
0
by: asmx126453 | last post by:
Hey mensen I am having some big troubles here i tryd solving it myself with internet for 2 days but i kind fix it. Its about this i have a DotNet project that alrydi is online and working for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.