Note that there are some explanatory texts on larger screens.

plurals
  1. POParameter.addwithvalue - ExecuteReader: CommandText property has not been initialized
    primarykey
    data
    text
    <p>I get the error <em>ExecuteReader: CommandText property has not been initialized</em> at the <code>adapter.fill(ds)</code> line. The weird thing is that if I replace <code>@user</code> with an actual string (e.g. 'name') it works perfectly fine, so something seems to be broken in the part that sets the parameter. </p> <p>I've tried to set the string both with and without <code>'</code>'s (i.e. @user/'@user'). I've also tried using both <code>=</code> and <code>like</code>. <code>User.Identity.Name.ToString()</code> has been tested to return the logged in user correctly by setting a textbox to it. </p> <p>Sorry for the non-English database variables and if this question has been answered somewhere. I've almost given up after half a dozen hours of searching, though (maybe I just suck at it).</p> <p>Relevant code:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.SqlClient; public partial class Bruker : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { String conn = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString; SqlConnection sql = new SqlConnection(conn); sql.Open(); SqlCommand command = new SqlCommand(conn); command.CommandText = "SELECT klubb.KlubbNavn FROM Klubber klubb inner join User_Klubber_Connection conn on Klubb.Klubb_Id = conn.Klubb_Id inner join aspnet_Users bruker on bruker.UserId = conn.UserId WHERE bruker.UserName = @user"; command.Parameters.AddWithValue("@user", User.Identity.Name.ToString()); command.Connection = sql; SetDropDownList(command); DropDownList1.SelectedIndex = 0; ChangeGridView(GetMembersOfClub(), sql); sql.Close(); } protected void SetDropDownList(SqlCommand command) { SqlDataAdapter adapter = new SqlDataAdapter(command); SqlCommandBuilder builder = new SqlCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds); DropDownList1.DataSource = ds; DropDownList1.DataTextField = "KlubbNavn"; DropDownList1.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.
 

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