SqlCommand is not defined.

G

Guest

Hello,

I could not call this sub routine because it says SqlConnection and SqlCommand is not defined.

Public Sub CreateMySqlCommand(ByVal myExecuteQuery As String, ByVal myConnection As SqlConnection)
Dim myCommand As New SqlCommand(myExecuteQuery, myConnection)
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub 'CreateMySqlCommand

What is problem?
Thanks,
Jim.
 
J

Jordan

try this:
Dim myCommand As SqlCommand = New SqlCommand(myExecuteQuery, myConnection)

I didn't test this, but it should work...

HTH
 
S

Sam Santiago

Are you importing the proper namespace in you class:

"Imports System.Data.SqlClient"

Or you could try fully qualifying the names in your method as a test. Use

System.Data.SqlClient.SqlCommand
vs just SqlCommand and SqlConnection.

Thanks,

Sam
 
G

Guest

I have another problem here, I call that sub-routing like: CreateMySqlCommand(sqlStr, SqlConnection1) where SqlConnection1 is my connection control name. It seems myCommand.ExecuteNonQuery() return -1. SqlConnection1 connection is working when I try to fill a dropdown list. How should I call the sub-routine?
Thanks,
Jim.
 
J

Jordan

ExecuteNonQuery is designed specifically to *not* return data.

I mean absolutely no disrespect, but have you even tried to look at online
help? You will typically get your answers much quicker if you go to online
help first. Instead of posting all these questions and waiting patiently for
answers, spending the same amount of time or less in online help would
provide you with most of what you need to know. For example, put
"ExecuteNonQuery" in Google and the following link is the first item listed:

http://msdn.microsoft.com/library/d...clientsqlcommandclassexecutenonquerytopic.asp


Trying to be helpful....



JIM.H. said:
I have another problem here, I call that sub-routing like:
CreateMySqlCommand(sqlStr, SqlConnection1) where SqlConnection1 is my
connection control name. It seems myCommand.ExecuteNonQuery() return -1.
SqlConnection1 connection is working when I try to fill a dropdown list. How
should I call the sub-routine?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top