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

tracy_pAsked:
Who is Participating?
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
Opps ... correction:

mycommand = New SqlCommand("Insert into register([name],[password]) values ('" + TextBox1.Text + "','" + TextBox2.Text + "')",myconn)
mycommand.ExecuteNonQuery()
 
0
 
prairiedogCommented:
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")

0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Hi tracy_p,

Try this way:

mycommand = New SqlCommand("Insert into register([name],[password]) values ('" + TextBox1.Text + "','" + TextBox2.Text + "'),myconn)
 mycommand.ExecuteNonQuery()
 
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
tracy_pAuthor Commented:
i tried both but same error message
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Try last one ... I have miss my post!
0
 
tracy_pAuthor Commented:
thanks jpaulino
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.