//SELECT ID van ingelogde gebruiker
            MySqlConnection cn = cn = new MySqlConnection("server=localhost; user id=bla; password=bla; database=project; Allow User Variables=True;");
            cn.Open();
            string selID = "SELECT LidID FROM gebruikers WHERE Gebruikersnaam=?Gebruikersnaam;";
            MySqlCommand cmd = new MySqlCommand(selID, cn);
            MySqlDataReader dr = default(MySqlDataReader);
            //Add parameters to get the username and password
            cmd.Parameters.Add("?Gebruikersnaam", MySqlDbType.VarChar);
            cmd.Parameters["?Gebruikersnaam"].Value = User.Identity.Name;

            int userID = 0;
            dr = cmd.ExecuteReader();
            dr.Read();
            userID = dr.GetInt32("LidID");
            dr.Close();

            Label1.Text = userID.ToString();

            //SELECT gebruiker aan hand van ID
            MySqlDataAdapter myDataAdapter = default(MySqlDataAdapter);
            DataSet myDataSet = default(DataSet);
            string selUser = "SELECT LidID FROM leden WHERE LidID=?LidID;";
            MySqlCommand cmd2 = new MySqlCommand(selUser, cn);
            cmd2.Parameters.Add("?LidID", MySqlDbType.Int32);
            cmd2.Parameters["?LidID"].Value = userID;

            myDataAdapter = new MySqlDataAdapter(selUser, cn);
            myDataSet = new DataSet();
            myDataAdapter.Fill(myDataSet, "leden");

            DetailsView1.DataSource = myDataSet;
            DetailsView1.DataBind();

This code gives me always an error:"Parameter '? ' must be defined" on "myDataAdapter.Fill(myDataSet, "leden");"

I want to get the ID from a user that is logged in in my table 'gebruikers' and then select with that ID the information of the users that is stored in 'leden'. And return that information in a detailsview.

But if I change selUser to "... WHERE LidID = 1 ...", it works.

If your store procedure doest have input param specify as

string selUser = "SELECT LidID FROM leden WHERE LidID=" + userID;   //Add input data

then remove line from 23 to 25 and check the status

If your store procedure doest have input param specify as

string selUser = "SELECT LidID FROM leden WHERE LidID=" + userID;   //Add input data

then remove line from 23 to 25 and check the status

Thanks, it works now

This question has already been answered. Start a new discussion instead.