Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NullReferenceException

Status
Not open for further replies.

kav123

Programmer
Jan 12, 2005
210
GB
Private Sub CreateParameter(ByVal paramValue As Object, ByVal paramName As String)


Dim param As New SqlParameter

param.Value = paramValue
param.ParameterName = paramName


p.Add(param.ParameterName, param.Value)

In the above bit of code i get a NullReference Exception with in the last line. Any ideas why it is happening. I am declaring the param object. I have got no idea what's going on.
 
Oh sorry forgot to mention, p is a sqlparametercollection and i have dimmed it like dim p as sqlparametercollection.

I think the problem is maybe i am not initialising it, but there is no external constructor for this collection.
 
Step through your code and put a breakpoint on the line that is failing. Then, post back here with the values of:

1) param.ParameterName
2) param.Value
3) p.Count


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Right, i did that and at the point where i am adding p.Add bit, both the param.Value and param.ParameterName are set to null.
 
That's fine and tha's old news, but my question to the forum is the way around it. Why is it null, when i am assigning them in the previous line only.
 
A bit more friendly would be nice.

Right, i did that and at the point where i am adding p.Add bit, both the param.Value and param.ParameterName are set to null.

So and what are the values of paramname and paramvalue at that time?

Christiaan Baes
Belgium

"My old site" - Me
 
Ok, yeah may be i should have been but i seem to have sorted it myself. Instead of using SqlParameterCollection i have used the following
sqlCmd.Parameter.CreateParamater(params to the function)
In the function CreateParameter i am doing the following:

Private Function CreateParameter(ByVal paramValue As Object, ByVal paramName As String, ByVal paramType As System.Data.SqlDbType, ByVal paramDirection As Data.ParameterDirection) As SqlParameter

Dim param As SqlParameter
param = New SqlParameter()

param.Value = paramValue
param.ParameterName = paramName

param.SqlDbType = paramType


param.Direction = paramDirection


CreateParameter = param
This works fine. Thanks, so much for the help and ca8msm, didnt mean to be rude, you know how it is when a bug gets to you:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top