Link to home
Start Free TrialLog in
Avatar of tracy_p
tracy_p

asked on

executeNonQuery: Connection property has not been initialized --vb.net2.0

Hi
when i am clicking submit button which inserts record into sqlserver ,i amexperiencing this error.
executeNonQuery: Connection property has not been initialized.
here is my code.
using .net2.0/vb.net/sql
Thank you
Dim myconn As SqlConnection
 Dim mycommand As SqlCommand
 myconn = New SqlConnection("Server=NAb;DataBase=conn; uid=sa;pwd=connect")
 myconn.Open()
 mycommand = New SqlCommand("Insert into register(name,password) values ('" + TextBox1.Text + "','" + TextBox2.Text + "'),myconn")
 mycommand.ExecuteNonQuery()
 myconn.Close()

Open in new window

Avatar of prairiedog
prairiedog
Flag of United States of America image

try to switch the order of these two lines:
myconn.Open()
 mycommand = New SqlCommand("Insert into register(name,password) values ('" + TextBox1.Text + "','" + TextBox2.Text + "'),myconn")

Avatar of Jorge Paulino
Hi tracy_p,

Try this way:

mycommand = New SqlCommand("Insert into register([name],[password]) values ('" + TextBox1.Text + "','" + TextBox2.Text + "'),myconn)
 mycommand.ExecuteNonQuery()
 
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tracy_p
tracy_p

ASKER

i tried both but same error message
Try last one ... I have miss my post!
Avatar of tracy_p

ASKER

thanks jpaulino
Also don't forget that password is an reserved word from SQL and you should always use this way [password]

Glad I could help and thanks for the grade!

jpaulino