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
IavbfaunOP2y 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
IavbfaunOP2y 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
IavbfaunOP2y ago
ı solve it but thank you a lot of 🥺
Want results from more Discord servers?
Add your server