ASP VB - How to update a database where the selected item is from a dropdown list using a datasource
<p>Hi I am new to ASP and was able to create a dropdown list which list all the items from my table <code>(DB2_INSTANCES)</code>.</p>

<p>Now I need to update a second table (<code>PROCESS</code>) with the value selected DB2_DSN. <code>The table does not allow Null values</code>.</p>

<p>If I use <code>"SelectedValue='&lt;%# Bind("DB2_DSN") %&gt;'</code> within my <code>asp:DropDownList</code> after I set the </p>

<p><code>DataSourceID="SqlDataSource6"  DataTextField="INSTANCE"  DataValueField="INSTANCE"</code></p>

<p>I get an error: </p>

<blockquote>
  <p>"'DropDownList6' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value "</p>
</blockquote>

<p>If I change to <code>"SelectedValue='&lt;%# Bind("INSTANCE") %&gt;'</code> within my <code>asp:DropDownList</code> after I set the </p>

<p><code>DataSourceID="SqlDataSource6"  DataTextField="INSTANCE"  DataValueField="INSTANCE"</code></p>

<p>I get an error: </p>

<blockquote>
  <p>"DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'INSTANCE'."</p>
</blockquote>

<p>If I remove the "<code>SelectedValue</code>..." I get the error:</p>

<blockquote>
  <p>Cannot insert the value NULL into column 'DB2_DSN', table 'xxx.dbo.PROCESS'; column does not allow nulls. UPDATE fails.
  The statement has been terminated.</p>
</blockquote>

<p>I also tried using the <code>DataBind()</code> but it also gives me an error. 
The other value <code>(FTP_IND)</code> works fine because it is listed/hardcoded.
Why does it work for <code>FTP_IND</code> and not for <code>DB2_DSN</code>?</p>

<p>First:</p>

<pre><code>&lt;asp:SqlDataSource ID="SqlDataSource3" runat="server" 
    ConnectionString="&lt;%$ ConnectionStrings:xxxConnectionString2 %&gt;" 
    DeleteCommand="DELETE FROM PROCESS WHERE NAME = @NAME AND ENVIRONMENT =   @ENVIRONMENT"
    SelectCommand="SELECT * FROM [PROCESS]" 
    UpdateCommand="UPDATE PROCESS SET ENVIRONMENT = @ENVIRONMENT, PROCESS_STATUS = @PROCESS_STATUS, IC_VALUE = @IC_VALUE, 
    FTP_IND = @FTP_IND, DB2_DSN = @DB2_DSN, DB2_REGION = @DB2_REGION, 
    ALERT_EMAIL = @ALERT_EMAIL, NOTIFY_EMAIL = @NOTIFY_EMAIL, DEBUG_INFO = @DEBUG_INFO, 
    LAST_UPDATE_DATE = CURRENT_TIMESTAMP, LAST_UPDATE_USERID = @UID, LAST_UPDATE_IP = @UIP WHERE (NAME = @NAME)"&gt;
        &lt;UpdateParameters&gt;
        &lt;asp:SessionParameter Name="UID" SessionField="User_ID" Type="String" /&gt;
        &lt;asp:SessionParameter Name="UIP" SessionField="User_IP" Type="String" /&gt;
        &lt;asp:Parameter Name="ENVIRONMENT" /&gt;
        &lt;asp:Parameter Name="PROCESS_STATUS" /&gt;
        &lt;asp:Parameter Name="IC_VALUE" /&gt;
        &lt;asp:Parameter Name="FTP_IND" /&gt;
        &lt;asp:Parameter Name="DB2_DSN" /&gt;
        &lt;asp:Parameter Name="DB2_REGION" /&gt;
        &lt;asp:Parameter Name="ALERT_EMAIL" /&gt;
        &lt;asp:Parameter Name="NOTIFY_EMAIL" /&gt;
        &lt;asp:Parameter Name="DEBUG_INFO" /&gt;
        &lt;asp:Parameter Name="NAME" /&gt;
    &lt;/UpdateParameters&gt;
&lt;/asp:SqlDataSource&gt;
&lt;asp:SqlDataSource ID="SqlDataSource6" runat="server" 
    ConnectionString="&lt;%$ ConnectionStrings:xxxConnectionString2 %&gt;" 
    SelectCommand="SELECT [INSTANCE] FROM [DB2_INSTANCES] ORDER BY [INSTANCE] ASC"&gt;
&lt;/asp:SqlDataSource&gt;
</code></pre>

<p>Second:</p>

<pre><code>&lt;asp:TemplateField HeaderText="FTP" SortExpression="FTP_IND"&gt;
            &lt;EditItemTemplate&gt;
                &lt;asp:DropDownList ID="DropDownList5" runat="server"  
                    SelectedValue='&lt;%# Bind("FTP_IND") %&gt;' 
                    ToolTip="Use this to turn off and on the FTP process" Font-Size="Small"&gt;
                    &lt;asp:ListItem&gt;N&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Y&lt;/asp:ListItem&gt;
                &lt;/asp:DropDownList&gt;
            &lt;/EditItemTemplate&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="Label11" runat="server" Text='&lt;%# Bind("FTP_IND") %&gt;' 
                    ToolTip="Indicates if FTP will take place" Font-Size="Small"&gt;
                &lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
            &lt;ItemStyle Font-Size="Small" HorizontalAlign="Center" /&gt;
        &lt;/asp:TemplateField&gt;

        &lt;asp:TemplateField HeaderText = "DB2 Instance" SortExpression="DB2_DSN"&gt;
            &lt;EditItemTemplate&gt;
                &lt;asp:DropDownList ID="DropDownList6" runat="server" 
                    ToolTip="Use this to choose the DB2 Instance" Font-Size="Small" 
                    DataSourceID="SqlDataSource6"
                    DataTextField="INSTANCE" 
                    DataValueField="INSTANCE"&gt;
                 &lt;/asp:DropDownList&gt;
            &lt;/EditItemTemplate&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="Label12" runat="server" Text='&lt;%# Bind("DB2_DSN") %&gt;'
                    ToolTip="Indicates the DB2 Instance being used" Font-Size="Small"&gt;
                &lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
            &lt;ItemStyle Font-Size="Small" HorizontalAlign="Center" /&gt;
</code></pre>
