[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2008-06-16
7
Medium Priority
?
1,500 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 2000 total points
ID: 21796877
Opps ... correction:

mycommand = New SqlCommand("Insert into register([name],[password]) values ('" + TextBox1.Text + "','" + TextBox2.Text + "')",myconn)
mycommand.ExecuteNonQuery()
 
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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