-4

I'm trying to insert a supplier to SQL Server but it always throws an exception on the line cmd.ExecuteNonQuery(). Really need some help!

Image

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Lam
  • 15
  • 2

1 Answers1

5

You never give the command object a connection, either do so in the SqlCommand() constructor or use command.Connection = con;

(An SqlCommand is disposable; you should create and use it within a using () {} construct to prevent resource leak)

Alex K.
  • 165,803
  • 30
  • 257
  • 277