Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:44:02+00:00 2026-06-01T17:44:02+00:00

I’m trying to create an option to select a specific entry in a SQL

  • 0

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.

Here’s my code behind:

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 > 0 AndAlso ds.Tables(0).Rows.Count > 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 > 0.0 Then
                    AmountVal.Text = "$" & (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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:44:04+00:00Added an answer on June 1, 2026 at 5:44 pm

    If I were doing this, I would change the code so that the contents in your click function are in a separate functions so that you can recall it easily from other functions. I would use a strongly typed object instead of a dataset for added symplicity. Also add a couple of string arguments to the “Load Data” function to accept monum and name strings.

    To find multiples, just check the count of what the database returns (datatable.rows.count or StronglyTypedObject.count)

    Next, create a invisible dropdownlist control and set it to visible if your row count is > 0.

    using Linq, binding the dropdownlist is fairly straight forward. Then call the new “load data” event on the onselectedindexchanged event passing the name selected along with the monumber.

    I will not go into filling a strongly typed object as this question is already asking for alot, but to get you started… The following code example is just that and should not be taken as the actual code you will use.

    Protected Sub GotMONum_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GotMO.Click
    
      loaddata(monum.text, "")
    end sub
    
    protected sub loaddata(byval monum as string, byval name as string)
      'your code here along with the following lines after:
      Dim MySelectQuery As String = ""
      myCommand.Parameters.AddWithValue("@MONum", MOTxt.Text)
    
      if not string.isnullorempty(name)
        MySelectQuery = "SELECT Name,ProdLine,NoRods,TieOffs FROM z_md_Outwrap WHERE MONumber = @MONum and Name = @name"
        mycommand.Parameters.AddWithValue("@Name", Name)
      else
        MySelectQuery = "SELECT Name,ProdLine,NoRods,TieOffs FROM z_md_Outwrap WHERE MONumber = @MONum "
      End If
      'again, instead using a dataset, convert it to a list(of StronglyTypedObject)
    
      if StronglyTypedObject.count > 0 then
         dropdownlist.visible = true
         dim dropdownlistcontents = (from a in StronglyTypedObject.AsEnumerable _
                                  Select a.Name).Distinct
         dropdownlist.datasource = dropdownlistcontents
         dropdownlist.databind
      end if
    end sub
    
    Protected Sub DDL_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) handles dropdownlist.selectedindexchanged
       loaddata(monum.text, "dropdownlist.selectedvalue")
    end sub
    

    Hopefully this gets you on your way… – Mutek

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.