“Parameter ?_1 has no default value” error when ExecuteReader

后端 未结 4 1291
情深已故
情深已故 2021-01-26 04:10

Having problem with the code below in a web service. Have searched for a solution but nothing that I have seen seems different to what I am doing below.

NB: The

4条回答
  •  余生分开走
    2021-01-26 04:34

    Duplicated of: OleDbCommand parameters order and priority

    The OLE DB .NET Provider does not support named parameters for passing parameters to an SQL statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used. For example:

    // Create SQL with ? for each parameter
    String sql = "SELECT Address FROM Adresses WHERE Country = ? AND City = ?";
    OleDbCommand command = new OleDbCommand(sql , connection);
    
    // Add to command each paramater VALUE by position. 
    // One parameter value for ?
    command.Parameters.Add("My City") ;
    command.Parameters.Add("My Country") ;
    

    http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.parameters.aspx

提交回复
热议问题