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!
Asked
Active
Viewed 212 times
-4
-
6You should show some code and the exception message for the community to be able to help you – alainlompo Nov 21 '16 at 13:58
-
1Really need some of your code!! – Dan Wilson Nov 21 '16 at 13:58
-
5Welcome to SO. please have a look at [how-to-ask](http://stackoverflow.com/help/how-to-ask) – swe Nov 21 '16 at 13:58
-
2Please copy and past code and error messages instead of posting images. – juharr Nov 21 '16 at 13:59
-
most of the folks you want to have help you will not deal with image only questions. see the link above provided by @swe – Neo Nov 21 '16 at 15:00
1 Answers
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