Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to tell it what fields to use as value and text.</p> <pre><code>ddlList.DataSource = sqlTa; ddlList.DataValueField = "ValueField"; ddlList.DataTextField = "TextField"; ddlList.DataBind(); </code></pre> <p>And your select statement is missing a ". It should be:</p> <pre><code>"Select Item FROM Calendar Where UserD='Test'" </code></pre> <p>An Example being:</p> <p>As ryan pointed out if you are pulling back one field then you can just do: </p> <pre><code> DataTable dtTable = new DataTable(); try { using (SqlConnection sqlConnection = new SqlConnection("Your connection")) { using (SqlCommand sqlCommand = new SqlCommand("Select Item FROM Calendar Where UserD='Test'", sqlConnection)) { sqlConnection.Open(); using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) { dtTable.Load(sqlDataReader); sqlDataReader.Close(); } } } } catch (Exception error) { throw error; } ddlList.DataSource = dtTable; ddlList.DataBind(); </code></pre> <p>But if you have more then one field then you can do this: </p> <pre><code> DataTable dtTable = new DataTable(); try { using (SqlConnection sqlConnection = new SqlConnection("Your connection")) { using (SqlCommand sqlCommand = new SqlCommand("Select Item, id FROM Calendar Where UserD='Test'", sqlConnection)) { sqlConnection.Open(); using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) { dtTable.Load(sqlDataReader); sqlDataReader.Close(); } } } } catch (Exception error) { throw error; } ddlList.DataSource = dtTable; ddlList.DataValueField = "id"; ddlList.DataTextField = "item"; ddlList.DataBind(); </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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