Solved

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

Posted on 2008-06-16
7
1,450 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
  • 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now