Good day! I am learning C # relatively recently ... In a book (C # Bible) I read an example:

adapter.DeleteCommand = new OleDbCommand("Delete from Peoples WHERE idKey = ?"); adapter.DeleteCommand.Parameters.Add("idKey", OleDbType.Integral, 10, "idKey"); adapter.DeleteCommand.Connection = connection; adapter.Update(dataset.Tables[0]); 

please explain to me where is the transfer of value to idKey key? I still do not understand where this is going to remove a specific entry ... In adapter.DeleteCommand.Parameters.Add, nothing of the kind happens.

    2 answers 2

    In your case, the value is not passed to the parameter. You need to use either OleDbParameter.AddWithValue , or do this:
    adapter.DeleteCommand = new OleDbCommand ("Delete from Peoples WHERE idKey =?");
    OleDbParameter param = adapter.DeleteCommand.CreateParameter ();
    param.ParameterName = "idKey";
    param.OleDbType = OleDbType.Integer;
    param.Value = 10; // pass the value
    adapter.DeleteCommand.Parameters.Add (param);
    adapter.DeleteCommand.Connection = connection;
    adapter.Update (dataset.Tables [0]);

    • Here is an example! Thank you, everything became clear. - IntegralAL

    As far as I remember, the value of the parameter will be substituted for the question mark in the request.

    // 10 is the value of the adapter.DeleteCommand.Parameters.Add ("idKey", OleDbType.Integral, 10, "idKey" parameter);

    • And where does the value of the parameter come from? In this code, I did not see this. - IntegralAL
    • updated answer. - Ivan Navoznov