-2

I have this code:

sqlCommand.Parameters.Add(new SqlParameter("@Title", "Title"));

and I'm receiving the error:

System.NullReferenceException: Object reference not set to an instance of an object.

Why? That's not the only Parameter that isn't working. Everything else works fine (the database, the connection string).

Bond
  • 15,435
  • 6
  • 28
  • 53
Vítor Norton
  • 102
  • 1
  • 10

1 Answers1

0

Seems like you forgot to instantiate the class.

SqlCommand command = new SqlCommand("SELECT * FROM table1",connection) command.Parameters.Add(new SqlParameter("@Title", "Title"))