Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamicly displayed DropDownList if multiple entry exists in table
    primarykey
    data
    text
    <p>I'm trying to create an option to select a specific entry in a SQL table if multiples exists. The Sub listed below is for a textbox (MOTxt) and a button (GotMO) for checking an MO# to pull from SQL. Based on the number entered, will populate other text boxes on the page with that row's data. There are exceptions to this, where the MONumber will be entered more than once with different data associated with each entry. So, here's my situation. If we have a duplicate MONumber listed in the table, it will populate the textboxes with the first entry it finds for an update. I would like to create a dynamic dropdownlist (that displays only if multiples are found) displaying the 'Name' field entries for each MONumber found, then once the correct name is selected from that list, to then populate the textboxes with that selected datarow.</p> <p>Here's my code behind:</p> <pre><code>Protected Sub GotMONum_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GotMO.Click Dim da As New SqlDataAdapter Dim ds As New DataSet Dim MOLength As String = MOTxt.Text Dim TieOffTemp As Integer Dim QTYTemp As Integer Dim MySelectQuery As String = "SELECT Name,ProdLine,NoRods,TieOffs FROM z_md_Outwrap WHERE MONumber = @MONum" Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("GLoomisDBConnectionString").ConnectionString) Dim myCommand As New SqlCommand(MySelectQuery, myConnection) Message2.InnerHtml = "" Message.InnerHtml = "" If (Me.MOTxt.Text = "") Then MsgBox("Please enter an MO Number to check") Else ' Fills fields based on MO Number myCommand.Parameters.AddWithValue("@MONum", MOTxt.Text) myConnection.Open() da.SelectCommand = myCommand da.Fill(ds, "tblData") myConnection.Close() If ds IsNot Nothing AndAlso ds.Tables.Count &gt; 0 AndAlso ds.Tables(0).Rows.Count &gt; 0 Then NameTxt.Text = ds.Tables("tblData").Rows(0).Item("Name") ProdLineTxt.Text = ds.Tables("tblData").Rows(0).Item("ProdLine") NoRodsTxt.Text = ds.Tables("tblData").Rows(0).Item("NoRods") TieOffsTxt.Text = ds.Tables("tblData").Rows(0).Item("TieOffs") If Integer.TryParse(NoRodsTxt.Text, QTYTemp) Then If Integer.TryParse(TieOffsTxt.Text, TieOffTemp) And TieOffTemp &gt; 0.0 Then AmountVal.Text = "$" &amp; (QTYTemp * TieOffTemp * 0.18) End If End If Else Message.InnerHtml = "No MO# found as entered. Please check for errors." Message.Style("color") = "red" End If End If End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload