1

In How to use a DataAdapter with stored procedure and parameter, the data adapter's selectCommand property has been used. Can the same be used if a stored procedure updates as well as retrieves data from a database?

Dovydas Šopa
  • 2,282
  • 8
  • 26
  • 34
Sam Wrayn
  • 63
  • 1
  • 1
  • 7

2 Answers2

0

On implementing it, and using the selectCommand (and not the property, it seems to work alright.

...

        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlQuery, sqlConnection);

        foreach (SqlParameter sqlParameter in sqlParameterCollection)
        {
            sqlCommand.Parameters.Add(new SqlParameter(sqlParameter.ParameterName, sqlParameter.Value));
        }
        sqlDataAdapter.SelectCommand = sqlCommand;
        DataSet dataSet = new DataSet();
        sqlDataAdapter.Fill(dataSet);

...

Sam Wrayn
  • 63
  • 1
  • 1
  • 7
0

The short answer is yes. Passing parameters to a stored procedure which updates and returns values is no different from the SqlDataAdapter side compared to a stored procedure that only returns values based on parameters passed in.

callisto
  • 4,921
  • 11
  • 51
  • 92