Hello: I'm working in Visual Studio 2012 and am creating a new website. I have a form that contains a formview control.
I need to have a dropdown that needs to populate from an sql table (table1). It will also allow users to enter new values.
If they select from an existing value, when saving, it will be inserting into a different table (table 2) then the one which it's populating from.
If the user is entering a new value into the dropdown, I will need it to insert the text into table 1 and after, use the new id it creates when inserting to insert into table 2.
I'm hoping that the combobox will be able to do all this so I'm giving it a try.
So far, I configured the combobox to populate from a sql server lookup table. Because the control will need to allow the user to enter new values so I set the dropdownstyle to simple.
I am having troubles however, figuring out how to configure it so that if the user enters a new value it will insert into table 1 and then table 2.
In the Source, here's my control and property values:
<asp:ComboBox ID="ddCompanyName" DropDownStyle="Simple" AutoCompleteMode="Append" runat="server" TabIndex="1" AutoPostBack="true" DataSourceID="SqlDataSourceCompanyName" DataTextField="CompanyName" DataValueField="CompanyNameId" ></asp:ComboBox>
Under the formview, I have the SqlDataSource set. One of the sources is used to populate the combobox:
<%-- Company Name--%> <asp:SqlDataSource ID="SqlDataSourceCompanyName" runat="server" CancelSelectOnNullParameter="false" ConnectionString="<%$ ConnectionStrings:SloanLEDLightingSystemsQuoteToolConnectionString %>" SelectCommand="SELECT CompanyName,
CompanyNameId FROM QuoteCompany_Lookup WHERE Active = 'true' order by CompanyName"> </asp:SqlDataSource>
Another is used when inserting, updating and selecting: I'm just going to list the insert one here: InsertCommand="INSERT INTO QuoteCustomerInformation(companynameId,contactname,email,phoneNumber,salespersonId,manufacturingRepresentativeId,pricingStructure,subtotalsForDimming,currency,billToAddress1,billToAddress2,billToAddress3,shipToAddress1,shipToAddress2,shipToAddress3,shipEarly,shipParital) VALUES(@companynameId,@contactname,@email,@phoneNumber,@salespersonId,@manufacturingRepresentativeId,@pricingStructure,@subtotalsForDimming,@currency,@billToAddress1,@billToAddress2,@billToAddress3,@shipToAddress1,@shipToAddress2,@shipToAddress3,@shipEarly,@shipParital); INSERT INTO QuoteCompany_Lookup(CompanyName) VALUES(CompanyName)">
if you look at the insert command, you'll see a 2 insert statements separated by a semi colon. I've never done this before, but read on the internet it should work when needing to use 2 insert statements.
when i run the form and try to insert a new value, it gives the message:
"Must declare the scalar variable "@CompanyName".
Does anyone know what this means? Also, am I even on the right track to doing this correctly?
Thank you for your help, Proctor