Solved

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

Posted on 2008-06-16
7
1,488 Views
Last Modified: 2013-11-07
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
Comment
Question by:tracy_p
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 21796787
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 21796842
Hi tracy_p,

Try this way:

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

Accepted Solution

by:
jpaulino earned 500 total points
ID: 21796877
Opps ... correction:

mycommand = New SqlCommand("Insert into register([name],[password]) values ('" + TextBox1.Text + "','" + TextBox2.Text + "')",myconn)
mycommand.ExecuteNonQuery()
 
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

Author Comment

by:tracy_p
ID: 21796899
i tried both but same error message
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21796903
Try last one ... I have miss my post!
0
 

Author Comment

by:tracy_p
ID: 21796932
thanks jpaulino
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21797055
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question