SQL Insert - How to how to combine more than one field value to a single column inser

I have a form with many form fields and controls, with some offering an “other” if a value does not meet the needs for the user. How can I bind the sql insert so that it will take the ddl selection along with the txt field selection for the “other” value? Even if the txt field is empty it should not be a big deal since the ddl would provide something other than null. Since the column in the db does not allow nulls. I’m using asp.net (vb) 3.5 sp1

Thanks in Advance!

Tim

I would suggest that you have seperate columns for the to fields. Otherwhise you are going to need to do it in code.

(ddlList.SelectedItem.Value!=“None”) ? ddlList.SelectedItem.Value : txtOther.Text;

Thanks for your reply, … I’m not sure I understand your suggestion.

I’ve copied some of my code for you to see what it is I am doing and trying to accomplish.

This shows one of the DropDownLists and where there is an “Other” selection the code behind displays the “other” textbox.


[COLOR=#0000ff][COLOR=#0000ff][SIZE=2]<[/SIZE][/COLOR][/COLOR][SIZE=2][COLOR=#a31515][COLOR=#a31515]td[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]DropDownList[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]ID[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="ddlArchiveFrequency"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]runat[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="server"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]AutoPostBack[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="True">[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]ListItem[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR]Please Select ...[COLOR=#0000ff][COLOR=#0000ff]</[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]ListItem[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]ListItem[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR]Weekly[COLOR=#0000ff][COLOR=#0000ff]</[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]ListItem[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]ListItem[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR]Monthly[COLOR=#0000ff][COLOR=#0000ff]</[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]ListItem[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]ListItem[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR]Other[COLOR=#0000ff][COLOR=#0000ff]</[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]ListItem[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]</[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]DropDownList[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#ff0000][COLOR=#ff0000]&nbsp;[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]TextBox[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]ID[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="txtArchiveFrequency"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]runat[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="server"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]Width[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="250px"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]ToolTip[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="(How often to backup? Weekly, Monthly etc...)"></[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]TextBox[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]</[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]td[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR]

[SIZE=2][COLOR=#0000ff][COLOR=#0000ff]Protected[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Sub[/COLOR][/COLOR] Page_Load([COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] sender [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Object[/COLOR][/COLOR], [COLOR=#0000ff][COLOR=#0000ff]ByVal[/COLOR][/COLOR] e [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] System.EventArgs) [COLOR=#0000ff][COLOR=#0000ff]Handles[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Me[/COLOR][/COLOR].Load[/SIZE]
[COLOR=#008000][COLOR=#008000][SIZE=2]'Check if Server function is Other & display additional text box[/SIZE][/COLOR]
[/COLOR][COLOR=#008000][COLOR=#008000][SIZE=2]'Check Archive requirements[/SIZE][/COLOR]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR] ddlArchiveFrequency.SelectedItem.Text = [COLOR=#a31515][COLOR=#a31515]"Other"[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Then[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2]txtArchiveFrequency.Visible = [COLOR=#0000ff][COLOR=#0000ff]True[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][COLOR=#0000ff][COLOR=#0000ff][SIZE=2]Else[/SIZE][/COLOR]
[/COLOR][SIZE=2]txtArchiveFrequency.Visible = [COLOR=#0000ff][COLOR=#0000ff]False[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]If[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]Sub[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR]

I’ve tried to keep things really simple and I am just showing one of the fields that I am dealing with, overall there are about 25 fields I am capturing and then storing in the DB.


[COLOR=#0000ff][COLOR=#0000ff][SIZE=2]<[/SIZE][/COLOR][/COLOR][SIZE=2][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]Button[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]ID[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="btnSubmit"[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]runat[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="server"[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]Text[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="Submit Request"[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]/>[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#ff0000]&nbsp;[/COLOR][/COLOR][/SIZE][COLOR=#ff0000]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]Button[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]ID[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="btnReset"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]runat[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="server"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]Text[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="Reset Form"[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]/>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]SqlDataSource[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]ID[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="dsSQLInsert"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]runat[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="server"[/COLOR][/COLOR] [/SIZE]
[SIZE=2][COLOR=#ff0000][COLOR=#ff0000]ConnectionString[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="[/COLOR][/COLOR]<%$ ConnectionStrings:ServerAssetsConnectionString %>[COLOR=#0000ff][COLOR=#0000ff]"[/COLOR][/COLOR] [/SIZE]
[SIZE=2][COLOR=#ff0000][COLOR=#ff0000]InsertCommand[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="INSERT INTO TSMRequests (ArchiveFrequency) VALUES (@ArchiveFrequency)"[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#ff0000][COLOR=#ff0000]SelectCommand[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="SELECT [ArchiveFrequency] FROM [TSMRequests]">[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]InsertParameters[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]<[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]FormParameter[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]FormField[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="ctl00$Content$ddlArchiveFrequency"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]Name[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="ArchiveFrequency"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]ConvertEmptyStringToNull[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="true"[/COLOR][/COLOR] [COLOR=#ff0000][COLOR=#ff0000]Type[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]="String"[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]/>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]</[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]InsertParameters[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR][SIZE=2][COLOR=#0000ff][COLOR=#0000ff]</[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]asp[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]:[/COLOR][/COLOR][COLOR=#a31515][COLOR=#a31515]SqlDataSource[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]>[/COLOR][/COLOR][/SIZE][COLOR=#0000ff]
[/COLOR]

So, as part of my insert parameters, can I combine two or more form fields values to insert into one column in the database?

Sorry, I cannot help you with that. As I never use SqlDataSources and do everything in code behind. But can u not just add the parameters from code behind on post back?

dsSQLInsert.InsertParameters.Add(“@ArchiveFrequency”, ddlArchiveFrequency.SelectedItem.Text!=“Other” ? ddlArchiveFrequency.SeletedItem.Text : txtArchiveFrequency.Text);

Not sure if that would work tho.