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

Hi experts,

I'm sure we've all seen the above message and usually its pretty clear where the error is coming from. But in the code below it's not obvious to me, so I need some help.

Here's the code:

 If Not cn.State = ConnectionState.Open Then
            cn.Open()
        End If
        Dim strSelect As String = ""

        Dim strUCode As String = txtUCode.Text
        Dim strLName As String = txtLNameREQ.Text
        Dim strMI As String = txtMI.Text
        Dim strFName As String = txtFNameREQ.Text
        Dim strAdd1 As String = txtAddress1REQ.Text
        Dim strAdd2 As String = txtAddress2.Text
        Dim strCity As String = txtCityREQ.Text
        Dim strST As String = txtSTREQ.Text
        Dim strZip As String = txtZipREQ.Text
        Dim strPH1 As String = txtPhone1REQ.Text
        Dim strPH2 As String = txtPhone2.Text
        Dim strCred As String = cbUserType.SelectedItem
        Dim strID As String = txtID.Text
        Dim dtExpire As DateTime = CDate(txtExpire.Text)
        Dim bitInitLogin As Boolean = True
        Dim strProvType As String = "U"
        Dim strDisc As String = txtDiscREQ.Text

        Dim sqlDA As New SqlClient.SqlDataAdapter(strSelect, cn)
        strSelect = "INSERT INTO tblUsersData UserCode, LName, FName, MI, MAddr1, MAddr2, MCity, MST, MZip, WPhone1, WPhone2, Credential, ID, Expiration, Prov_Type, initial_login, Discipline " & _
                                            "VALUES (@UserCode, @LName, @FName, @MI, @MAddr1, @MAddr2, @MCity, @MST, @MZip, @WPhone1, @WPhone2, @Credential, @ID, @Expiration, @Prov_Type, @initial_login, @Disc)"

        sqlDA.InsertCommand.Parameters.AddWithValue("@UserCode", strUCode)
        sqlDA.InsertCommand.Parameters.AddWithValue("@LName", strLName)
        sqlDA.InsertCommand.Parameters.AddWithValue("@FName", strFName)
        sqlDA.InsertCommand.Parameters.AddWithValue("@MI", strMI)
        sqlDA.InsertCommand.Parameters.AddWithValue("@MAddr1", strAdd1)
        sqlDA.InsertCommand.Parameters.AddWithValue("@MAddr2", strAdd2)
        sqlDA.InsertCommand.Parameters.AddWithValue("@MCity", strCity)
        sqlDA.InsertCommand.Parameters.AddWithValue("@MST", strST)
        sqlDA.InsertCommand.Parameters.AddWithValue("@MZip", strZip)
        sqlDA.InsertCommand.Parameters.AddWithValue("@WPhone1", strPH1)
        sqlDA.InsertCommand.Parameters.AddWithValue("@WPhone2", strPH2)
        sqlDA.InsertCommand.Parameters.AddWithValue("@Credential", strCred)
        sqlDA.InsertCommand.Parameters.AddWithValue("@ID", strID)
        sqlDA.InsertCommand.Parameters.AddWithValue("@Expiration", dtExpire)
        sqlDA.InsertCommand.Parameters.AddWithValue("@Prov_Type", strProvType)
        sqlDA.InsertCommand.Parameters.AddWithValue("@initial_login", bitInitLogin)
        sqlDA.InsertCommand.Parameters.AddWithValue("@Disc", strDisc)

        Try
            sqlDA.SelectCommand.CommandText = strSelect
            sqlDA.SelectCommand.ExecuteNonQuery()
        Catch err As SqlClient.SqlException
            MessageBox.Show("An error occurred in AddUser - " & err.Message)
        End Try
        cn.Close()
This is the first time I've used AddWithValue in the Parameters, so I'm not 100% on the proper syntax but I believe it's correct.. Any help would be appreciated,

Jack

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

Take a look at the TASKKILL command, it supports wildcards in the image name that you wantto kill andmay be able to do what you need.

http://technet.microsoft.com/en-us/library/cc725602%28WS.10%29.aspx

~bp
Random Solutions  
 
programming4us programming4us