Which ADO.NET method is used to add parameters to a SqlCommand object?

  • Parameters.Add()
  • Parameters.AddWithValue()
  • Parameters.Create()
  • Parameters.Insert()
The correct method to add parameters to a SqlCommand object in ADO.NET is Parameters.AddWithValue(). This method adds a parameter with a specified name and value to the SqlCommand.Parameters collection. It automatically detects the data type of the parameter based on the value provided, simplifying the process of parameter creation. By using this method, developers can easily incorporate parameterized queries into their applications, improving security and performance by preventing SQL injection attacks and promoting efficient query execution.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *