error-object reference not set to an instance of the object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I have the code below and am trying to use a stored procedure that excepts 2 integer inputs
I have also attempted to create the data adapter without the wizard. The line
da.InsertCommand().Parameters("@DataItemID").Value() = tempint1 causes the run time error

***************actual code**************************************************
Dim da As New SqlDataAdapte
Dim cmd As New SqlCommand("dml$parmins_data_item_destination"
tempint = data_item_id 'data_item_id is from the previous for
dest_string = lst_bx_dest.SelectedValu
tempint1 = dest_string ' cast to intege
' tempint = lst_bx_dest.SelectedInde
With cm
cmd.Connection = Me.SqlConnection
cmd.CommandType = CommandType.StoredProcedur
cmd.Parameters.Add((New System.Data.SqlClient.SqlParameter("@DataItemID", System.Data.SqlDbType.Int, 4))
cmd.Parameters.Add((New System.Data.SqlClient.SqlParameter("@DestinationID", System.Data.SqlDbType.Int, 4))
da.InsertCommand().Parameters("@DataItemID").Value() = tempint
da.InsertCommand().Parameters("@DestinationID").Value() = tempin
da.InsertCommand = cm
End Wit
***************end code*******************************************************
 
Hi Paul:

What value is the SelectedValue? Have you stepped through it with the
Debugger? I'm guessing you may not have the valuemember property set or
this is in form load where there's no SelectedValue. To test this theory
why not use Debug.Assert(lst_bx_dest.SelectedValue is Nothing) right at the
top of the proc. If the assertion fails you'll know this is the problem.
Also you can set all of that in one line
da.InsertCommand().Parameters("@DataItemID").Value() =
CType(lst_bx_dest.SelectedValue.ToString, Integer)

However if this is nothing you'll still have a problem. Also, do you have
Option Strict On? Doesn't look like you do. If not, you'll definitely want
to do this b/c it will give you much better performance and will stop a lot
of logic bugs associated with implicit type conversion.

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

www.devbuzz.com
www.knowdotnet.com
http://www.msmvps.com/williamryan/
Paul said:
Hi I have the code below and am trying to use a stored procedure that excepts 2 integer inputs.
I have also attempted to create the data adapter without the wizard. The line
da.InsertCommand().Parameters("@DataItemID").Value() = tempint1 causes the run time error.

***************actual code***************************************************
Dim da As New SqlDataAdapter
Dim cmd As New SqlCommand("dml$parmins_data_item_destination")
tempint = data_item_id 'data_item_id is from the previous form
dest_string = lst_bx_dest.SelectedValue
tempint1 = dest_string ' cast to integer
' tempint = lst_bx_dest.SelectedIndex
With cmd
cmd.Connection = Me.SqlConnection1
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add((New
System.Data.SqlClient.SqlParameter("@DataItemID", System.Data.SqlDbType.Int,
4)))
cmd.Parameters.Add((New
System.Data.SqlClient.SqlParameter("@DestinationID",
System.Data.SqlDbType.Int, 4)))
da.InsertCommand().Parameters("@DataItemID").Value() = tempint1
da.InsertCommand().Parameters("@DestinationID").Value() = tempint
da.InsertCommand = cmd
End With
***************end
code*******************************************************
 
Back
Top