Note that there are some explanatory texts on larger screens.

plurals
  1. POBug in my code or Am not doing it right
    text
    copied!<p>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 <a href="https://stackoverflow.com/questions/11592266/asp-dropdownlist-databind-from-database">sample on stackover site</a> but still mine is not working and no error is displayed. <a href="http://aspdotnetcode.blogspot.com/2010/10/dropdownlist.html" rel="nofollow noreferrer">Another sample is described here</a>! Here is my codes:HTML</p> <pre><code> &lt;li&gt; &lt;asp:Label runat="server" ID ="lblVisits"&gt;Visit Number&lt;/asp:Label&gt; &lt;asp:DropDownList ID="DropDownList2" runat="server" Height="16px" Width="174px" style="margin-left: 46px"&gt; &lt;asp:ListItem Text=""&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Value=""&gt;&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;/li&gt; </code></pre> <p>CodeBehind:</p> <pre><code>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("&lt;script language=javascript&gt;alert('Patient Number not Found.');&lt;/script&gt;"); ErrorMessage.Text = "Error Occurred" + excep.Message.ToString(); } finally { con.Close(); } } </code></pre>
 

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