469,268 Members | 975 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

SqlCommand is not defined.

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.

Nov 18 '05 #1
5 3989
try this:
Dim myCommand As SqlCommand = New SqlCommand(myExecuteQuery, myConnection)

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

HTH


"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
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.

Nov 18 '05 #2
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

--
_______________________________
Sam Santiago
ss*******@n0spam-SoftiTechture.com

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
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.

Nov 18 '05 #3
it works fine now. how should I check if this sql string returns anything or not?

"Sam Santiago" wrote:
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

--
_______________________________
Sam Santiago
ss*******@n0spam-SoftiTechture.com

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
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.


Nov 18 '05 #4

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.
"Sam Santiago" wrote:
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

--
_______________________________
Sam Santiago
ss*******@n0spam-SoftiTechture.com

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
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.


Nov 18 '05 #5
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/de...querytopic.asp
Trying to be helpful....

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...

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.
"Sam Santiago" wrote:
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

--
_______________________________
Sam Santiago
ss*******@n0spam-SoftiTechture.com

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
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.


Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Donnie Darko | last post: by
10 posts views Thread by Henrik Dahl | last post: by
1 post views Thread by Tom | last post: by
3 posts views Thread by Jason Huang | last post: by
reply views Thread by Agnes | last post: by
1 post views Thread by job | last post: by
2 posts views Thread by menyki | last post: by
reply views Thread by menyki | last post: by
6 posts views Thread by Frank Hauptlorenz | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.