473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Help with object reference error

I'm not sure why I keep getting this error, "Object reference not set to an
instance of an object".

Private Function somefunction() as string
Dim MyCurrentClass As New Class1

Try
For i As Integer = 0 To LinkResults.Length - 1
With MyCurrentClass.SqlCmd_Insert_LinkVB
.CommandType = System.Data.CommandType.StoredProcedure
'error occurs here

-- do something --
End Function

The above code is in Class1. If there is a problem with the reference to
the object instance, why doesn't this line throw an error at
With MyCurrentClass.SqlCmd_Insert_LinkVB

The new class has been created, which means there is an instance available.
What am I doing wrong?

Thanks,
Brett
Nov 21 '05 #1
7 1549
The error "Object reference not set to an instance of an object" always
means (afaik) that you are referencing an object that is set to nothing.
You are correct that you create a new version of Class1 and MyCurrentClass
is set to something, that is not what the runtime is complaining about. It
is complaining that the object returned by
MyCurrentClass.SqlCmd_Insert_LinkVB is set to nothing.

So you need to find out why the SqlCmd_Insert_LinkVB method returns nothing.

Hope this helps.
Chris

"Brett" <no@spam.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
I'm not sure why I keep getting this error, "Object reference not set to
an instance of an object".

Private Function somefunction() as string
Dim MyCurrentClass As New Class1

Try
For i As Integer = 0 To LinkResults.Length - 1
With MyCurrentClass.SqlCmd_Insert_LinkVB
.CommandType = System.Data.CommandType.StoredProcedure
'error occurs here

-- do something --
End Function

The above code is in Class1. If there is a problem with the reference to
the object instance, why doesn't this line throw an error at
With MyCurrentClass.SqlCmd_Insert_LinkVB

The new class has been created, which means there is an instance
available. What am I doing wrong?

Thanks,
Brett

Nov 21 '05 #2
Ok, I see the problem now that you describe it this way. I first call a sub
named, InitailizeDatabaseConnections()

In the sub I do this:

Me.SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlCmd_Insert_LinkVB.Connection = Me.mycn

In the watches, I see that Me.SqlCmd_Insert_LinkVB does have values. Once I
leave InitailizeDatabaseConnections(), Me.SqlCmd_Insert_LinkVB is set to
Nothing. I've moved the above declarations out of the sub and into the
class. However, I declare the parameters within the sub:

Me.SqlCmd_Insert_LinkVB.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@message_id", System.Data.SqlDbType.Int,
4))

The above is just one parameter declaration but it keeps loosing its value
after I move out of InitailizeDatabaseConnections(). I must do the
assignments with a sub. How else can this be done so other subs will have
access to the params?

I'd like to declare all the params in one sub then do assignments to the
params in another sub.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:uT**************@TK2MSFTNGP15.phx.gbl...
The error "Object reference not set to an instance of an object" always
means (afaik) that you are referencing an object that is set to nothing.
You are correct that you create a new version of Class1 and MyCurrentClass
is set to something, that is not what the runtime is complaining about.
It is complaining that the object returned by
MyCurrentClass.SqlCmd_Insert_LinkVB is set to nothing.

So you need to find out why the SqlCmd_Insert_LinkVB method returns
nothing.

Hope this helps.
Chris

"Brett" <no@spam.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
I'm not sure why I keep getting this error, "Object reference not set to
an instance of an object".

Private Function somefunction() as string
Dim MyCurrentClass As New Class1

Try
For i As Integer = 0 To LinkResults.Length - 1
With MyCurrentClass.SqlCmd_Insert_LinkVB
.CommandType = System.Data.CommandType.StoredProcedure
'error occurs here

-- do something --
End Function

The above code is in Class1. If there is a problem with the reference to
the object instance, why doesn't this line throw an error at
With MyCurrentClass.SqlCmd_Insert_LinkVB

The new class has been created, which means there is an instance
available. What am I doing wrong?

Thanks,
Brett


Nov 21 '05 #3
Well you are doing more than you describe in the sub. Where do you declare
SqlCmd_Insert_LinkVB. Since you didnt show enough code I can't tell you
what you are doing wrong. I will give you an example of how to make it work
though.
'Note: I typed this all in here, syntax here will occur, not tested
Public Class Class1

Private m_SqlCmd_Insert_LinkVB as SqlCommand 'This is the local variable
to the class

Private Sub InitailizeDatabaseConnections
'This creates a new version of the command object.
m_SqlCmd_Insert_LinkVB = New SqlCommand

'Now the command object is vaild, load up your settings
Me.m_SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.m_SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.m_SqlCmd_Insert_LinkVB.Connection = Me.mycn
End Sub

'This property gets called from an outside class to return an object
Public ReadOnly Property SqlCmd_Insert_LinkVB
Get
Return m_SqlCmd_Insert_LinkVB
end get
End Property

End Class

Hope this helps
Chris
"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ok, I see the problem now that you describe it this way. I first call a
sub named, InitailizeDatabaseConnections()

In the sub I do this:

Me.SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlCmd_Insert_LinkVB.Connection = Me.mycn

In the watches, I see that Me.SqlCmd_Insert_LinkVB does have values. Once
I leave InitailizeDatabaseConnections(), Me.SqlCmd_Insert_LinkVB is set to
Nothing. I've moved the above declarations out of the sub and into the
class. However, I declare the parameters within the sub:

Me.SqlCmd_Insert_LinkVB.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@message_id",
System.Data.SqlDbType.Int, 4))

The above is just one parameter declaration but it keeps loosing its value
after I move out of InitailizeDatabaseConnections(). I must do the
assignments with a sub. How else can this be done so other subs will have
access to the params?

I'd like to declare all the params in one sub then do assignments to the
params in another sub.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:uT**************@TK2MSFTNGP15.phx.gbl...
The error "Object reference not set to an instance of an object" always
means (afaik) that you are referencing an object that is set to nothing.
You are correct that you create a new version of Class1 and
MyCurrentClass is set to something, that is not what the runtime is
complaining about. It is complaining that the object returned by
MyCurrentClass.SqlCmd_Insert_LinkVB is set to nothing.

So you need to find out why the SqlCmd_Insert_LinkVB method returns
nothing.

Hope this helps.
Chris

"Brett" <no@spam.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
I'm not sure why I keep getting this error, "Object reference not set to
an instance of an object".

Private Function somefunction() as string
Dim MyCurrentClass As New Class1

Try
For i As Integer = 0 To LinkResults.Length - 1
With MyCurrentClass.SqlCmd_Insert_LinkVB
.CommandType =
System.Data.CommandType.StoredProcedure 'error occurs here

-- do something --
End Function

The above code is in Class1. If there is a problem with the reference
to the object instance, why doesn't this line throw an error at
With MyCurrentClass.SqlCmd_Insert_LinkVB

The new class has been created, which means there is an instance
available. What am I doing wrong?

Thanks,
Brett



Nov 21 '05 #4
That's what I'm doing - declaring them as private in the class. I haven't
created the initializeDatabaseConnection() sub yet. I have everything in
one sub for simplicity. Now I keep getting this error "Exception has been
thrown by the target of an invocation".

on this line
..ExecuteNonQuery()

Here is the code:
With SqlCmd_spamBlacklist_Insert
.CommandType =
System.Data.CommandType.StoredProcedure
.Parameters("@messageid").Value = messageid
.Parameters("@listname").Value = ListName
.Parameters("@listurl").Value = ListURL
.ExecuteNonQuery()
End With

It's a very generic error. How do I go about debugging it?

Thanks,
Brett
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:er**************@TK2MSFTNGP10.phx.gbl...
Well you are doing more than you describe in the sub. Where do you
declare SqlCmd_Insert_LinkVB. Since you didnt show enough code I can't
tell you what you are doing wrong. I will give you an example of how to
make it work though.
'Note: I typed this all in here, syntax here will occur, not tested
Public Class Class1

Private m_SqlCmd_Insert_LinkVB as SqlCommand 'This is the local
variable to the class

Private Sub InitailizeDatabaseConnections
'This creates a new version of the command object.
m_SqlCmd_Insert_LinkVB = New SqlCommand

'Now the command object is vaild, load up your settings
Me.m_SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.m_SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.m_SqlCmd_Insert_LinkVB.Connection = Me.mycn
End Sub

'This property gets called from an outside class to return an object
Public ReadOnly Property SqlCmd_Insert_LinkVB
Get
Return m_SqlCmd_Insert_LinkVB
end get
End Property

End Class

Hope this helps
Chris
"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ok, I see the problem now that you describe it this way. I first call a
sub named, InitailizeDatabaseConnections()

In the sub I do this:

Me.SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlCmd_Insert_LinkVB.Connection = Me.mycn

In the watches, I see that Me.SqlCmd_Insert_LinkVB does have values.
Once I leave InitailizeDatabaseConnections(), Me.SqlCmd_Insert_LinkVB is
set to Nothing. I've moved the above declarations out of the sub and
into the class. However, I declare the parameters within the sub:

Me.SqlCmd_Insert_LinkVB.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@message_id",
System.Data.SqlDbType.Int, 4))

The above is just one parameter declaration but it keeps loosing its
value after I move out of InitailizeDatabaseConnections(). I must do
the assignments with a sub. How else can this be done so other subs will
have access to the params?

I'd like to declare all the params in one sub then do assignments to the
params in another sub.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:uT**************@TK2MSFTNGP15.phx.gbl...
The error "Object reference not set to an instance of an object" always
means (afaik) that you are referencing an object that is set to nothing.
You are correct that you create a new version of Class1 and
MyCurrentClass is set to something, that is not what the runtime is
complaining about. It is complaining that the object returned by
MyCurrentClass.SqlCmd_Insert_LinkVB is set to nothing.

So you need to find out why the SqlCmd_Insert_LinkVB method returns
nothing.

Hope this helps.
Chris

"Brett" <no@spam.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
I'm not sure why I keep getting this error, "Object reference not set
to an instance of an object".

Private Function somefunction() as string
Dim MyCurrentClass As New Class1

Try
For i As Integer = 0 To LinkResults.Length - 1
With MyCurrentClass.SqlCmd_Insert_LinkVB
.CommandType =
System.Data.CommandType.StoredProcedure 'error occurs here

-- do something --
End Function

The above code is in Class1. If there is a problem with the reference
to the object instance, why doesn't this line throw an error at
With MyCurrentClass.SqlCmd_Insert_LinkVB

The new class has been created, which means there is an instance
available. What am I doing wrong?

Thanks,
Brett



Nov 21 '05 #5
I have it working now. I needed to declare this way in the public class
area:

Friend WithEvents SqlCmd_Insert_LinkVB As System.Data.SqlClient.SqlCommand

Then in the sub, I do this:
Me.SqlCmd_Insert_LinkVB = New System.Data.SqlClient.SqlCommand

Thanks,
Brett

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
That's what I'm doing - declaring them as private in the class. I haven't
created the initializeDatabaseConnection() sub yet. I have everything in
one sub for simplicity. Now I keep getting this error "Exception has been
thrown by the target of an invocation".

on this line
.ExecuteNonQuery()

Here is the code:
With SqlCmd_spamBlacklist_Insert
.CommandType =
System.Data.CommandType.StoredProcedure
.Parameters("@messageid").Value = messageid
.Parameters("@listname").Value = ListName
.Parameters("@listurl").Value = ListURL
.ExecuteNonQuery()
End With

It's a very generic error. How do I go about debugging it?

Thanks,
Brett
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:er**************@TK2MSFTNGP10.phx.gbl...
Well you are doing more than you describe in the sub. Where do you
declare SqlCmd_Insert_LinkVB. Since you didnt show enough code I can't
tell you what you are doing wrong. I will give you an example of how to
make it work though.
'Note: I typed this all in here, syntax here will occur, not tested
Public Class Class1

Private m_SqlCmd_Insert_LinkVB as SqlCommand 'This is the local
variable to the class

Private Sub InitailizeDatabaseConnections
'This creates a new version of the command object.
m_SqlCmd_Insert_LinkVB = New SqlCommand

'Now the command object is vaild, load up your settings
Me.m_SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.m_SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.m_SqlCmd_Insert_LinkVB.Connection = Me.mycn
End Sub

'This property gets called from an outside class to return an object
Public ReadOnly Property SqlCmd_Insert_LinkVB
Get
Return m_SqlCmd_Insert_LinkVB
end get
End Property

End Class

Hope this helps
Chris
"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ok, I see the problem now that you describe it this way. I first call a
sub named, InitailizeDatabaseConnections()

In the sub I do this:

Me.SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlCmd_Insert_LinkVB.Connection = Me.mycn

In the watches, I see that Me.SqlCmd_Insert_LinkVB does have values.
Once I leave InitailizeDatabaseConnections(), Me.SqlCmd_Insert_LinkVB is
set to Nothing. I've moved the above declarations out of the sub and
into the class. However, I declare the parameters within the sub:

Me.SqlCmd_Insert_LinkVB.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@message_id",
System.Data.SqlDbType.Int, 4))

The above is just one parameter declaration but it keeps loosing its
value after I move out of InitailizeDatabaseConnections(). I must do
the assignments with a sub. How else can this be done so other subs
will have access to the params?

I'd like to declare all the params in one sub then do assignments to the
params in another sub.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:uT**************@TK2MSFTNGP15.phx.gbl...
The error "Object reference not set to an instance of an object" always
means (afaik) that you are referencing an object that is set to
nothing. You are correct that you create a new version of Class1 and
MyCurrentClass is set to something, that is not what the runtime is
complaining about. It is complaining that the object returned by
MyCurrentClass.SqlCmd_Insert_LinkVB is set to nothing.

So you need to find out why the SqlCmd_Insert_LinkVB method returns
nothing.

Hope this helps.
Chris

"Brett" <no@spam.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
> I'm not sure why I keep getting this error, "Object reference not set
> to an instance of an object".
>
> Private Function somefunction() as string
> Dim MyCurrentClass As New Class1
>
> Try
> For i As Integer = 0 To LinkResults.Length - 1
> With MyCurrentClass.SqlCmd_Insert_LinkVB
> .CommandType =
> System.Data.CommandType.StoredProcedure 'error occurs here
>
> -- do something --
> End Function
>
> The above code is in Class1. If there is a problem with the reference
> to the object instance, why doesn't this line throw an error at
> With MyCurrentClass.SqlCmd_Insert_LinkVB
>
> The new class has been created, which means there is an instance
> available. What am I doing wrong?
>
> Thanks,
> Brett
>



Nov 21 '05 #6
Two questions.

1: Why are you using the WithEvents keyword. This is fine if you are
consuming event fired byt he object, but I doubt you are.

2: Why use friends? I assume you are doing this so objects outside of the
class can access the variable. This is fine, but I prefer the way I showed
you in my example by declaring the object as private and then giving access
to it in a method. This lets you make changes in the future easier.

Chris

"Brett" <no@spam.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
I have it working now. I needed to declare this way in the public class
area:

Friend WithEvents SqlCmd_Insert_LinkVB As System.Data.SqlClient.SqlCommand

Then in the sub, I do this:
Me.SqlCmd_Insert_LinkVB = New System.Data.SqlClient.SqlCommand

Thanks,
Brett

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
That's what I'm doing - declaring them as private in the class. I
haven't created the initializeDatabaseConnection() sub yet. I have
everything in one sub for simplicity. Now I keep getting this error
"Exception has been thrown by the target of an invocation".

on this line
.ExecuteNonQuery()

Here is the code:
With SqlCmd_spamBlacklist_Insert
.CommandType =
System.Data.CommandType.StoredProcedure
.Parameters("@messageid").Value =
messageid
.Parameters("@listname").Value = ListName
.Parameters("@listurl").Value = ListURL
.ExecuteNonQuery()
End With

It's a very generic error. How do I go about debugging it?

Thanks,
Brett
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:er**************@TK2MSFTNGP10.phx.gbl...
Well you are doing more than you describe in the sub. Where do you
declare SqlCmd_Insert_LinkVB. Since you didnt show enough code I can't
tell you what you are doing wrong. I will give you an example of how to
make it work though.
'Note: I typed this all in here, syntax here will occur, not tested
Public Class Class1

Private m_SqlCmd_Insert_LinkVB as SqlCommand 'This is the local
variable to the class

Private Sub InitailizeDatabaseConnections
'This creates a new version of the command object.
m_SqlCmd_Insert_LinkVB = New SqlCommand

'Now the command object is vaild, load up your settings
Me.m_SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.m_SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.m_SqlCmd_Insert_LinkVB.Connection = Me.mycn
End Sub

'This property gets called from an outside class to return an object
Public ReadOnly Property SqlCmd_Insert_LinkVB
Get
Return m_SqlCmd_Insert_LinkVB
end get
End Property

End Class

Hope this helps
Chris
"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ok, I see the problem now that you describe it this way. I first call
a sub named, InitailizeDatabaseConnections()

In the sub I do this:

Me.SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlCmd_Insert_LinkVB.Connection = Me.mycn

In the watches, I see that Me.SqlCmd_Insert_LinkVB does have values.
Once I leave InitailizeDatabaseConnections(), Me.SqlCmd_Insert_LinkVB
is set to Nothing. I've moved the above declarations out of the sub
and into the class. However, I declare the parameters within the sub:

Me.SqlCmd_Insert_LinkVB.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@message_id",
System.Data.SqlDbType.Int, 4))

The above is just one parameter declaration but it keeps loosing its
value after I move out of InitailizeDatabaseConnections(). I must do
the assignments with a sub. How else can this be done so other subs
will have access to the params?

I'd like to declare all the params in one sub then do assignments to
the params in another sub.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:uT**************@TK2MSFTNGP15.phx.gbl...
> The error "Object reference not set to an instance of an object"
> always means (afaik) that you are referencing an object that is set to
> nothing. You are correct that you create a new version of Class1 and
> MyCurrentClass is set to something, that is not what the runtime is
> complaining about. It is complaining that the object returned by
> MyCurrentClass.SqlCmd_Insert_LinkVB is set to nothing.
>
> So you need to find out why the SqlCmd_Insert_LinkVB method returns
> nothing.
>
> Hope this helps.
> Chris
>
>
>
> "Brett" <no@spam.com> wrote in message
> news:ee**************@TK2MSFTNGP09.phx.gbl...
>> I'm not sure why I keep getting this error, "Object reference not set
>> to an instance of an object".
>>
>> Private Function somefunction() as string
>> Dim MyCurrentClass As New Class1
>>
>> Try
>> For i As Integer = 0 To LinkResults.Length - 1
>> With MyCurrentClass.SqlCmd_Insert_LinkVB
>> .CommandType =
>> System.Data.CommandType.StoredProcedure 'error occurs here
>>
>> -- do something --
>> End Function
>>
>> The above code is in Class1. If there is a problem with the
>> reference to the object instance, why doesn't this line throw an
>> error at
>> With MyCurrentClass.SqlCmd_Insert_LinkVB
>>
>> The new class has been created, which means there is an instance
>> available. What am I doing wrong?
>>
>> Thanks,
>> Brett
>>
>
>



Nov 21 '05 #7
How is the property called:

Public ReadOnly Property SqlCmd_Insert_LinkVB
Get
Return m_SqlCmd_Insert_LinkVB
end get
End Property

Do I just reference:
Me.SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure

or is some type of initialization needed?

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:OO**************@TK2MSFTNGP10.phx.gbl...
Two questions.

1: Why are you using the WithEvents keyword. This is fine if you are
consuming event fired byt he object, but I doubt you are.

2: Why use friends? I assume you are doing this so objects outside of
the class can access the variable. This is fine, but I prefer the way I
showed you in my example by declaring the object as private and then
giving access to it in a method. This lets you make changes in the future
easier.

Chris

"Brett" <no@spam.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
I have it working now. I needed to declare this way in the public class
area:

Friend WithEvents SqlCmd_Insert_LinkVB As
System.Data.SqlClient.SqlCommand

Then in the sub, I do this:
Me.SqlCmd_Insert_LinkVB = New System.Data.SqlClient.SqlCommand

Thanks,
Brett

"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
That's what I'm doing - declaring them as private in the class. I
haven't created the initializeDatabaseConnection() sub yet. I have
everything in one sub for simplicity. Now I keep getting this error
"Exception has been thrown by the target of an invocation".

on this line
.ExecuteNonQuery()

Here is the code:
With SqlCmd_spamBlacklist_Insert
.CommandType =
System.Data.CommandType.StoredProcedure
.Parameters("@messageid").Value =
messageid
.Parameters("@listname").Value = ListName
.Parameters("@listurl").Value = ListURL
.ExecuteNonQuery()
End With

It's a very generic error. How do I go about debugging it?

Thanks,
Brett
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:er**************@TK2MSFTNGP10.phx.gbl...
Well you are doing more than you describe in the sub. Where do you
declare SqlCmd_Insert_LinkVB. Since you didnt show enough code I can't
tell you what you are doing wrong. I will give you an example of how
to make it work though.
'Note: I typed this all in here, syntax here will occur, not tested
Public Class Class1

Private m_SqlCmd_Insert_LinkVB as SqlCommand 'This is the local
variable to the class

Private Sub InitailizeDatabaseConnections
'This creates a new version of the command object.
m_SqlCmd_Insert_LinkVB = New SqlCommand

'Now the command object is vaild, load up your settings
Me.m_SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
Me.m_SqlCmd_Insert_LinkVB.CommandType =
System.Data.CommandType.StoredProcedure
Me.m_SqlCmd_Insert_LinkVB.Connection = Me.mycn
End Sub

'This property gets called from an outside class to return an object
Public ReadOnly Property SqlCmd_Insert_LinkVB
Get
Return m_SqlCmd_Insert_LinkVB
end get
End Property

End Class

Hope this helps
Chris
"Brett" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> Ok, I see the problem now that you describe it this way. I first call
> a sub named, InitailizeDatabaseConnections()
>
> In the sub I do this:
>
> Me.SqlCmd_Insert_LinkVB.CommandText = "dbo.[Insert_LinkVB]"
> Me.SqlCmd_Insert_LinkVB.CommandType =
> System.Data.CommandType.StoredProcedure
> Me.SqlCmd_Insert_LinkVB.Connection = Me.mycn
>
> In the watches, I see that Me.SqlCmd_Insert_LinkVB does have values.
> Once I leave InitailizeDatabaseConnections(), Me.SqlCmd_Insert_LinkVB
> is set to Nothing. I've moved the above declarations out of the sub
> and into the class. However, I declare the parameters within the sub:
>
> Me.SqlCmd_Insert_LinkVB.Parameters.Add(New
> System.Data.SqlClient.SqlParameter("@message_id",
> System.Data.SqlDbType.Int, 4))
>
> The above is just one parameter declaration but it keeps loosing its
> value after I move out of InitailizeDatabaseConnections(). I must do
> the assignments with a sub. How else can this be done so other subs
> will have access to the params?
>
> I'd like to declare all the params in one sub then do assignments to
> the params in another sub.
>
> Thanks,
> Brett
>
> "Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
> wrote in message news:uT**************@TK2MSFTNGP15.phx.gbl...
>> The error "Object reference not set to an instance of an object"
>> always means (afaik) that you are referencing an object that is set
>> to nothing. You are correct that you create a new version of Class1
>> and MyCurrentClass is set to something, that is not what the runtime
>> is complaining about. It is complaining that the object returned by
>> MyCurrentClass.SqlCmd_Insert_LinkVB is set to nothing.
>>
>> So you need to find out why the SqlCmd_Insert_LinkVB method returns
>> nothing.
>>
>> Hope this helps.
>> Chris
>>
>>
>>
>> "Brett" <no@spam.com> wrote in message
>> news:ee**************@TK2MSFTNGP09.phx.gbl...
>>> I'm not sure why I keep getting this error, "Object reference not
>>> set to an instance of an object".
>>>
>>> Private Function somefunction() as string
>>> Dim MyCurrentClass As New Class1
>>>
>>> Try
>>> For i As Integer = 0 To LinkResults.Length - 1
>>> With MyCurrentClass.SqlCmd_Insert_LinkVB
>>> .CommandType =
>>> System.Data.CommandType.StoredProcedure 'error occurs here
>>>
>>> -- do something --
>>> End Function
>>>
>>> The above code is in Class1. If there is a problem with the
>>> reference to the object instance, why doesn't this line throw an
>>> error at
>>> With MyCurrentClass.SqlCmd_Insert_LinkVB
>>>
>>> The new class has been created, which means there is an instance
>>> available. What am I doing wrong?
>>>
>>> Thanks,
>>> Brett
>>>
>>
>>
>
>



Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
4
by: Frawls | last post by:
Hi, I get the following error when trying to run a search on my aspx site, this error only occours if the product im searching for does not exist. Can anybody explain this please and help me...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
8
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error for some of my web application users but not others??? Even though the application runs from a central webserver??? Thanks for...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
13
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.