• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1502
  • Last Modified:

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

0
tracy_p
Asked:
tracy_p
  • 4
  • 2
1 Solution
 
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
 
jpaulinoCommented:
Hi tracy_p,

Try this way:

mycommand = New SqlCommand("Insert into register([name],[password]) values ('" + TextBox1.Text + "','" + TextBox2.Text + "'),myconn)
 mycommand.ExecuteNonQuery()
 
0
 
jpaulinoCommented:
Opps ... correction:

mycommand = New SqlCommand("Insert into register([name],[password]) values ('" + TextBox1.Text + "','" + TextBox2.Text + "')",myconn)
mycommand.ExecuteNonQuery()
 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
tracy_pAuthor Commented:
i tried both but same error message
0
 
jpaulinoCommented:
Try last one ... I have miss my post!
0
 
tracy_pAuthor Commented:
thanks jpaulino
0
 
jpaulinoCommented:
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now