-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
  • 732,580
  • 175
  • 1,330
  • 1,459
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.
  • 171,639
  • 30
  • 264
  • 288