error: object reference not set to an instance of an object

error: object reference not set to an instance of an object

Post by prasann » Thu, 28 Feb 2002 12:45:53



Hi,

This is my code but i am getting an error:

object reference not set to an instance of an object

  Dim mySelectText As String = "SELECT * FROM equ_ren"
            Dim mySelectConn As String = "Integrated
Security=SSPI; Persist Security Info=False;Initial
Catalog=equipment_rental;Data Source=GMSSGCESD001"
            Dim myDataAdapter As New SqlDataAdapter
(mySelectText, mySelectConn)
            Dim InsertCmd As String = "Update equ_ren set
type = '" & type.text & "', brand = '" & brand.text & "',
model = '" & model.text & "',"
                InsertCmd = InsertCmd & " serial_no = '"
& sn_no.text & "', status = '" & status.text & "',
renting_company = '" & renting_company.text & "',"
                InsertCmd = InsertCmd & " end_user = '" &
end_user.text & "', inst_loc = '" & inst_loc.text & "',
inst_date =  " & inst_dt.text & ","
                InsertCmd = InsertCmd & " rent_bill_date
= " & rent_bill_dt.text & " ,bill_period = '" &
bill_period.text & "',"
                InsertCmd = InsertCmd & " inst_billed
= '" & inst_billed.SelectedItem.Value & "', lan_IP= '" &
lan_IP.text & "' where serial_no = '" & sn_no.text & "';"

            myDataAdapter.UpdateCommand.CommandText =
InsertCmd
            myDataAdapter.UpdateCommand.Connection = CType
(myDataAdapter.SelectCommand.Connection, SqlConnection)

thanks for sparing ur valuable time.

cheers

prasanna

 
 
 

error: object reference not set to an instance of an object

Post by Yilei Wa » Fri, 01 Mar 2002 05:54:40


Prasanna,

The code example in the documentation seems incorrect.  Since the
UpdateCommand property is not instantiated as an SqlCommand object, any
settings of its properties would be invalid.  To fix this error, just
replace the last two lines of code with:

Dim update As New SqlCommand()
update.CommandText = InsertCmd
update.Connection = CType(myDataAdapter.SelectCommand.Connection,
SqlConnection)
myDataAdapter.UpdateCommand = update

Thanks and have a good day!

Yilei Wang [MS]

****************************************************************************
This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure?  For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
****************************************************************************