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 9243221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:45:43+00:00 2026-06-18T08:45:43+00:00

I have been struggling with the usecase for two days now.All i need was

  • 0

I have been struggling with the usecase for two days now.All i need was to read Patient’S VisitNumber from the patient visit table and populate the dropdownlist given the Patient Number.After some much research these two links address almost the same issue.I did as described here sample on stackover site but still mine is not working and no error is displayed. Another sample is described here!
Here is my codes:HTML

  <li>
            <asp:Label runat="server" ID ="lblVisits">Visit Number</asp:Label>
            <asp:DropDownList ID="DropDownList2" runat="server" Height="16px" Width="174px" style="margin-left: 46px">
                <asp:ListItem Text=""></asp:ListItem>
                <asp:ListItem Value=""></asp:ListItem>
            </asp:DropDownList>
  </li>    

CodeBehind:

protected void btn_search_Click(object sender, EventArgs e)
    {
        string connect = System.Configuration.ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        string num = txtPatientNumber.ToString();
        SqlConnection con = new SqlConnection(connect);
        string Statement = "SELECT Visit_Number FROM Visit "
          + "WHERE Patient_Number=@Patient_Number";
        SqlCommand cmd = new SqlCommand(Statement, con);
        cmd.Parameters.AddWithValue("@Patient_Number", num);

        SqlDataReader reader;

        try
        {
            con.Open();
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                DropDownList2.DataSource = reader;
                DropDownList2.DataTextField = reader["Visit_Number"].ToString();
                DropDownList2.DataValueField = reader["Visit_Number"].ToString();
                DropDownList2.DataBind();
            }
            reader.Close();
        }
        catch (SqlException excep)
        {
            //Response.Write("<script language=javascript>alert('Patient Number not Found.');</script>");
            ErrorMessage.Text = "Error Occurred" + excep.Message.ToString();
        }
        finally
        {
            con.Close();
        }

    }
  • 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-18T08:45:45+00:00Added an answer on June 18, 2026 at 8:45 am

    Problem lies here:

    while (reader.Read())
    {
       DropDownList2.DataSource = reader;
       DropDownList2.DataTextField = reader["Visit_Number"].ToString();
       DropDownList2.DataValueField = reader["Visit_Number"].ToString();
       DropDownList2.DataBind();
    }
    

    Your are using .DataTextField and .DataValueField wrong. This is how it should look like:

    DropDownList2.DataTextField = "Visit_Number";
    DropDownList2.DataValueField ="Visit_Number";
    

    Also you should not rebind DropDownList for every row returned from db. So remove while (reader.Read()).

    Final code:

    DropDownList2.DataSource = reader;
    DropDownList2.DataTextField = "Visit_Number";
    DropDownList2.DataValueField = "Visit_Number";
    DropDownList2.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this for days now. I am trying to register
I have been struggling to make this work for a couple of days now.
I have been struggling with that for 4 days now. I have a very
I have been struggling with this for several days now and I ran out
I have been struggling with this for a few days. I need somebody to
I have been struggling with the RestKit since 15 days now. Once I receive
I have been struggling for almost three days now on this task, and I
I have been struggling with this for a while now. given a set of
I have been struggling with this error for more than two hours: error: aggregate
I have been struggling for a few days trying to find out how come

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.