C
C#2y ago
iavbfaun

Visual studio and SQL

ı am taking System.InvalidOperationException: 'ExecuteNonQuery: Connection property has not been initialized.' eror can you help me 😦
6 Replies
mtreit
mtreit2y ago
You need to pass your SqlConnection object in the constructor of SqlCommand
iavbfaun
iavbfaun2y ago
How can ı do 😦
mtreit
mtreit2y ago
using var cmd = new SqlCommand(sql, conn); Alternately you can set the Connection property of the SqlCommand instance
cmd.Connection = conn;
cmd.Connection = conn;
But probably easier to just pass it in the constructor.
iavbfaun
iavbfaun2y ago
thank u ı will try ıt ❤️ ❤️ sory for my newbie. I tryd but I couldn't do what you said 😦
mtreit
mtreit2y ago
Why not?
iavbfaun
iavbfaun2y ago
ı solve it but thank you a lot of 🥺