• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2059
  • Last Modified:

Error Fill: SelectCommand.Connection property has not been initialized

Looking for some suggestions on the reason for this error.


An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

Additional information: Fill: SelectCommand.Connection property has not been initialized.

Thanks in advance.

Regard
Tim


0
TimSweet220
Asked:
TimSweet220
  • 3
  • 3
  • 2
  • +1
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
As it says on the tin, you havent assigned a Connection to the command.

Post your code and we may be able to tell you where the problem is.
0
 
Bill_PSCCommented:
It sounds like your connection is not initialized, use something like this;

Dim con As New SqlConnection(connectionstring)
            Dim CMD As New SqlCommand(selectSQL, con)
            con.Open()
0
 
TimSweet220Author Commented:
This the end of the sub were it stops and generates the error.

  'Grab Address Information

            ds = New DataSet("tblCurrAddress")
            'SqlAddressAdapter.SelectCommand = Me.SqlSelectAddress
            SqlAddressAdapter.SelectCommand.Parameters("@ABRID").Value = vABRID
            SqlAddressAdapter.Fill(ds, "tblCurrAddress")

            If ds.Tables("tblCurrAddress").Rows.Count() > 0 Then
                '1st do the Work address
                For i = 0 To (ds.Tables("tblCurrAddress").Rows.Count() - 1)
                    'Populate only mailing address on screen.
                    If ds.Tables("tblCurrAddress").Rows(i)(1) = "Work" Then 'And ds.Tables("tblCurrAddress").Rows(i)(10) = True Then
                        Me.txtTypeWork.Text = "Work"
                        Me.txtNewWAddress1.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(2)
                        Me.txtNewWAddress2.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(3)
                        Me.txtNewWAddress3.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(4)
                        Me.txtNewWCity.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(5)
                        Me.txtNewWState.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(6)
                        Me.txtNewWZipcode.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(7)
                        Me.txtNewWCountry.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(8)
                        Me.txtAddressId.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(12)
                    End If
                    'Now do Home Address
                    'Else
                    If Trim(ds.Tables("tblCurrAddress").Rows(i)(1)) = "Home" Then 'And ds.Tables("tblCurrAddress").Rows(i)(10) = True Then
                        Me.txtTypeHome.Text = "Home"
                        Me.txtNewHAddress1.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(2)
                        Me.txtNewHAddress2.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(3)
                        Me.txtNewHAddress3.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(4)
                        Me.txtNewHCity.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(5)
                        Me.txtNewHState.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(6)
                        Me.txtNewHZip.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(7)
                        Me.txtNewHCountry.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(8)
                        Me.txtAddressId.Text = "" & ds.Tables("tblCurrAddress").Rows(i)(12)
                    End If
                Next
            End If
        End If
    End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
TimSweet220Author Commented:
I use this and call it in several places..when necessary
 Private Sub SQLReconnect()

        Select Case Me.SqlConnection1.State

            Case ConnectionState.Broken

                Me.SqlConnection1.Close()

                Me.SqlConnection1.Open()

            Case ConnectionState.Closed

                Me.SqlConnection1.Open()

        End Select

    End Sub

But the connection should keep breaking.

0
 
Carl TawnSystems and Integration DeveloperCommented:
Its the part before this block:

           ds = New DataSet("tblCurrAddress")
            'SqlAddressAdapter.SelectCommand = Me.SqlSelectAddress
            SqlAddressAdapter.SelectCommand.Parameters("@ABRID").Value = vABRID
            SqlAddressAdapter.Fill(ds, "tblCurrAddress")

That you need to look at. How are you creating your Command object ? Or are you simply assigning values straight to the DataAdapter ?
0
 
YZlatCommented:
use this function:

Function GetConnection(ByVal strConn As String) As SqlConnection
        Try
            conn = New SqlConnection(strConn)
            conn.Open()
        Catch ex As SqlException
                       Console.Write("SQL ERROR: " & ex.Message)
        Catch ex As Exception
         
            Console.Write("ERROR: " & ex.Message)
        End Try
        GetConnection = conn
    End Function

then you can have something like that in your code:

Dim conn As SqlConnection          
conn=GetConnection("your connection string")
 Dim cmd As New SqlCommand(sqlStr, conn)
0
 
TimSweet220Author Commented:
Well unfortunately I can't give any more then 500 points per question..but here is the entire sub...

Private Sub AddressData()
        'SQLReconnect()
        Dim i As Integer
        Dim vContactType, VDetails, VUser, vAddressUpdate, vContactUpdate

        VUser = System.Environment.UserName

        If (Me.txtNewWEMail.Text = "") And (Me.txtNewWFax.Text = "") And (Me.txtNewWPhone.Text = "") And (Me.txtNewHPhone.Text = "") And (Me.txtNewHCell.Text = "") And (Me.txtNewHEMail.Text = "") Then
            vContactUpdate = 0
        Else
            vContactUpdate = 1
        End If

        If (Me.txtNewWAddress1.Text <> "") Then
            If (Me.txtNewWCity.Text = "") Or (Me.txtNewWState.Text = "") Or (Me.txtNewWZipcode.Text = "") Then
                MsgBox("Please enter in a Work complete address.", MsgBoxStyle.OKOnly, "Error")
            Else
                ' Update Current Address values as Inactive
                'Work Address 1st
                'Only Update if Address1 populated and if Prior active address existed.
                If (Me.txtNewWAddress1.Text <> "") And Me.txtAddressId.Text <> "" Then      ' And (Me.txtNewHAddress1.Text <> "") Then
                    'SqlAddressAdapter.SelectCommand = SqlUpdateAddress

                    SqlAddressAdapter.UpdateCommand.Parameters("@ABRID").Value = Status.FABRID
                    SqlAddressAdapter.UpdateCommand.Parameters("@AddressID").Value = Me.txtAddressId.Text
                    SqlAddressAdapter.UpdateCommand.Parameters("@Type").Value = "Work"
                    SqlAddressAdapter.UpdateCommand.Parameters("@User").Value = VUser
                    SqlAddressAdapter.UpdateCommand.Parameters("@Process").Value = "ABRApp"
                    SqlAddressAdapter.UpdateCommand.ExecuteNonQuery()
                End If
            End If
        End If

        If (Me.txtNewHAddress1.Text <> "") Then
            If (Me.txtNewHCity.Text = "") Or (Me.txtNewHState.Text = "") Or (Me.txtNewHZip.Text = "") Then
                MsgBox("Please enter in a Home complete address.", MsgBoxStyle.OKOnly, "Error")
            Else

                'Home Address Now
                'Only Update if Address1 populated and if Prior active address existed.
                If (Me.txtNewHAddress1.Text <> "") And Me.txtHAddressId.Text <> "" Then      ' And (Me.txtNewHCity.Text <> "") And (Me.txtNewHCountry.Text <> "") Then
                    'SqlAddressAdapter.SelectCommand = SqlUpdateAddress
                    SqlAddressAdapter.UpdateCommand.Parameters("@ABRID").Value = Status.FABRID
                    SqlAddressAdapter.UpdateCommand.Parameters("@AddressID").Value = Me.txtHAddressId.Text
                    SqlAddressAdapter.UpdateCommand.Parameters("@Type").Value = "Home"
                    SqlAddressAdapter.UpdateCommand.Parameters("@User").Value = VUser
                    SqlAddressAdapter.UpdateCommand.Parameters("@Process").Value = "ABRApp"
                    SqlAddressAdapter.UpdateCommand.ExecuteNonQuery()

                End If
            End If
        End If


        'Insert New Address Information
        If Me.txtNewWAddress1.Text <> "" Then
            'SqlAddressAdapter.SelectCommand = SqlInsertAddress
            SqlAddressAdapter.InsertCommand.Parameters("@ABR_ID").Value = Status.FABRID
            SqlAddressAdapter.InsertCommand.Parameters("@Type").Value = "Work"
            SqlAddressAdapter.InsertCommand.Parameters("@Address1").Value = Me.txtNewWAddress1.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Address2").Value = Me.txtNewWAddress2.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Address3").Value = Me.txtNewWAddress3.Text
            SqlAddressAdapter.InsertCommand.Parameters("@City").Value = Me.txtNewWCity.Text
            SqlAddressAdapter.InsertCommand.Parameters("@State").Value = Me.txtNewWState.Text
            SqlAddressAdapter.InsertCommand.Parameters("@PostalCode").Value = Me.txtNewWZipcode.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Country").Value = Me.txtNewWCountry.Text
            If Me.chkWAddressMailing.Checked = True Then
                SqlAddressAdapter.InsertCommand.Parameters("@Mailing").Value = 1
            Else
                SqlAddressAdapter.InsertCommand.Parameters("@Mailing").Value = 0
            End If
            SqlAddressAdapter.InsertCommand.Parameters("@Process").Value = "ABR App"
            SqlAddressAdapter.InsertCommand.Parameters("@User").Value = VUser
            SqlAddressAdapter.InsertCommand.ExecuteNonQuery()
        End If

        If Me.txtNewHAddress1.Text <> "" Then
            'SqlAddressAdapter.SelectCommand = SqlInsertAddress
            SqlAddressAdapter.InsertCommand.Parameters("@ABR_ID").Value = Status.FABRID
            SqlAddressAdapter.InsertCommand.Parameters("@Type").Value = "Home"
            SqlAddressAdapter.InsertCommand.Parameters("@Address1").Value = Me.txtNewHAddress1.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Address2").Value = Me.txtNewHAddress2.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Address3").Value = Me.txtNewHAddress3.Text
            SqlAddressAdapter.InsertCommand.Parameters("@City").Value = Me.txtNewHCity.Text
            SqlAddressAdapter.InsertCommand.Parameters("@State").Value = Me.txtNewHState.Text
            SqlAddressAdapter.InsertCommand.Parameters("@PostalCode").Value = Me.txtNewHZip.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Country").Value = Me.txtNewHCountry.Text
            If Me.chkHAddressMailing.Checked = True Then
                SqlAddressAdapter.InsertCommand.Parameters("@Mailing").Value = 1
            Else
                SqlAddressAdapter.InsertCommand.Parameters("@Mailing").Value = 0
            End If
            SqlAddressAdapter.InsertCommand.Parameters("@Process").Value = "ABR App"
            SqlAddressAdapter.InsertCommand.Parameters("@User").Value = VUser
            SqlAddressAdapter.InsertCommand.ExecuteNonQuery()
        End If

        If vContactUpdate = 1 Then
            'Update Current Work Contact Information as Inactive
            'Loop throught for each contact type
            'Only Update if Type populated and if Prior Type existed
            For i = 1 To 6
                Select Case i
                    Case 1         'Office
                        vContactType = "Office Phone"
                        If Me.txtNewWPhone.Text <> "" Then
                            VDetails = Me.txtNewWPhone.Text
                        Else
                            VDetails = ""
                        End If
                    Case 2         'Fax
                        vContactType = "Fax Phone"
                        If Me.txtNewWFax.Text <> "" Then
                            VDetails = Me.txtNewWFax.Text
                        Else
                            VDetails = ""
                        End If
                    Case 3         'Email
                        vContactType = "Work eMail"
                        If Me.txtNewWEMail.Text <> "" Then
                            VDetails = Me.txtNewWEMail.Text
                        Else
                            VDetails = ""
                        End If
                    Case 4         'Office
                        If Me.txtNewHPhone.Text <> "" Then
                            vContactType = "Home Phone"
                            VDetails = Me.txtNewHPhone.Text
                        Else
                            VDetails = ""
                        End If
                    Case 5         'Cell
                        If Me.txtNewHCell.Text <> "" Then
                            vContactType = "Cell Phone"
                            VDetails = Me.txtNewHCell.Text
                        Else
                            VDetails = ""
                        End If
                    Case 6         'Email
                        If Me.txtNewHEMail.Text <> "" Then
                            vContactType = "Home eMail"
                            VDetails = Me.txtNewHEMail.Text
                        Else
                            VDetails = ""
                        End If
                End Select

                ' Make sure New Values given before updating to inactive
                If VDetails <> "" Then
                    'SqlContactAdapter.SelectCommand = SqlUpdateContact
                    SqlContactAdapter.UpdateCommand.Parameters("@ABRID").Value = Status.FABRID
                    SqlContactAdapter.UpdateCommand.Parameters("@Type").Value = vContactType
                    SqlContactAdapter.UpdateCommand.Parameters("@Process").Value = "ABRApp"
                    SqlContactAdapter.UpdateCommand.Parameters("@User").Value = VUser
                    SqlContactAdapter.UpdateCommand.ExecuteNonQuery()
                End If
            Next
        End If

        'Insert New Contact Information
        'Loop throught for each contact type
        For i = 1 To 3
            Select Case i
                Case 1     'Office
                    If (Me.txtNewWPhone.Text <> "") Then
                        vContactType = "Office Phone"
                        VDetails = Me.txtNewWPhone.Text
                    Else : VDetails = ""
                    End If
                Case 2     'Fax
                    If (Me.txtNewWFax.Text <> "") Then
                        vContactType = "Fax Phone"
                        VDetails = Me.txtNewWFax.Text
                    Else : VDetails = ""
                    End If
                Case 3     'Work Email
                    If (Me.txtNewWEMail.Text <> "") Then
                        vContactType = "Work eMail"
                        VDetails = Me.txtNewWEMail.Text
                    Else : VDetails = ""
                    End If
                Case 4     'Home
                    'If the the new matches the old then details =""
                    If Me.txtNewHPhone.Text <> "" Then
                        vContactType = "Home Phone"
                        VDetails = Me.txtNewHPhone.Text
                    Else
                        VDetails = ""
                    End If
                Case 5     'Cell
                    'If the the new matches the old then details =""
                    If Me.txtNewHCell.Text <> "" Then
                        vContactType = "Cell Phone"
                        VDetails = Me.txtNewHCell.Text
                    Else
                        VDetails = ""
                    End If
                Case 6     'Home Email
                    If Me.txtNewHEMail.Text <> "" Then
                        vContactType = "Home eMail"
                        VDetails = Me.txtNewHEMail.Text
                    Else
                        VDetails = ""
                    End If
                Case Else : VDetails = ""
            End Select

            ' Make sure New Values given before updating to inactive
            If VDetails <> "" Then
                'Insert New Contact Information
                'SqlContactAdapter.SelectCommand = SqlInsertContact
                SqlContactAdapter.InsertCommand.Parameters("@ABRID").Value = Status.FABRID
                SqlContactAdapter.InsertCommand.Parameters("@Type").Value = vContactType
                SqlContactAdapter.InsertCommand.Parameters("@Details").Value = VDetails
                SqlContactAdapter.InsertCommand.Parameters("@PrimaryContact").Value = 0
                SqlContactAdapter.InsertCommand.Parameters("@Process").Value = "ABRApp"
                SqlContactAdapter.InsertCommand.Parameters("@User").Value = System.Environment.UserName
                SqlContactAdapter.InsertCommand.ExecuteNonQuery()
            End If
        Next

    End Sub
0
 
YZlatCommented:
Private Sub AddressData()
        Dim conn As SqlConnection
        conn = GetConnection("connection string")

        Dim SqlAddressAdapter = New SqlDataAdapter(sqlQuery, conn)

        'SQLReconnect()
        Dim i As Integer
        Dim vContactType, VDetails, VUser, vAddressUpdate, vContactUpdate

        VUser = System.Environment.UserName

        If (Me.txtNewWEMail.Text = "") And (Me.txtNewWFax.Text = "") And (Me.txtNewWPhone.Text = "") And (Me.txtNewHPhone.Text = "") And (Me.txtNewHCell.Text = "") And (Me.txtNewHEMail.Text = "") Then
            vContactUpdate = 0
        Else
            vContactUpdate = 1
        End If

        If (Me.txtNewWAddress1.Text <> "") Then
            If (Me.txtNewWCity.Text = "") Or (Me.txtNewWState.Text = "") Or (Me.txtNewWZipcode.Text = "") Then
                MsgBox("Please enter in a Work complete address.", MsgBoxStyle.OKOnly, "Error")
            Else
                ' Update Current Address values as Inactive
                'Work Address 1st
                'Only Update if Address1 populated and if Prior active address existed.
                If (Me.txtNewWAddress1.Text <> "") And Me.txtAddressId.Text <> "" Then      ' And (Me.txtNewHAddress1.Text <> "") Then
                    'SqlAddressAdapter.SelectCommand = SqlUpdateAddress

                    SqlAddressAdapter.UpdateCommand.Parameters("@ABRID").Value = Status.FABRID
                    SqlAddressAdapter.UpdateCommand.Parameters("@AddressID").Value = Me.txtAddressId.Text
                    SqlAddressAdapter.UpdateCommand.Parameters("@Type").Value = "Work"
                    SqlAddressAdapter.UpdateCommand.Parameters("@User").Value = VUser
                    SqlAddressAdapter.UpdateCommand.Parameters("@Process").Value = "ABRApp"
                    SqlAddressAdapter.UpdateCommand.ExecuteNonQuery()
                End If
            End If
        End If

        If (Me.txtNewHAddress1.Text <> "") Then
            If (Me.txtNewHCity.Text = "") Or (Me.txtNewHState.Text = "") Or (Me.txtNewHZip.Text = "") Then
                MsgBox("Please enter in a Home complete address.", MsgBoxStyle.OKOnly, "Error")
            Else

                'Home Address Now
                'Only Update if Address1 populated and if Prior active address existed.
                If (Me.txtNewHAddress1.Text <> "") And Me.txtHAddressId.Text <> "" Then      ' And (Me.txtNewHCity.Text <> "") And (Me.txtNewHCountry.Text <> "") Then
                    'SqlAddressAdapter.SelectCommand = SqlUpdateAddress
                    SqlAddressAdapter.UpdateCommand.Parameters("@ABRID").Value = Status.FABRID
                    SqlAddressAdapter.UpdateCommand.Parameters("@AddressID").Value = Me.txtHAddressId.Text
                    SqlAddressAdapter.UpdateCommand.Parameters("@Type").Value = "Home"
                    SqlAddressAdapter.UpdateCommand.Parameters("@User").Value = VUser
                    SqlAddressAdapter.UpdateCommand.Parameters("@Process").Value = "ABRApp"
                    SqlAddressAdapter.UpdateCommand.ExecuteNonQuery()

                End If
            End If
        End If


        'Insert New Address Information
        If Me.txtNewWAddress1.Text <> "" Then
            'SqlAddressAdapter.SelectCommand = SqlInsertAddress
            SqlAddressAdapter.InsertCommand.Parameters("@ABR_ID").Value = Status.FABRID
            SqlAddressAdapter.InsertCommand.Parameters("@Type").Value = "Work"
            SqlAddressAdapter.InsertCommand.Parameters("@Address1").Value = Me.txtNewWAddress1.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Address2").Value = Me.txtNewWAddress2.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Address3").Value = Me.txtNewWAddress3.Text
            SqlAddressAdapter.InsertCommand.Parameters("@City").Value = Me.txtNewWCity.Text
            SqlAddressAdapter.InsertCommand.Parameters("@State").Value = Me.txtNewWState.Text
            SqlAddressAdapter.InsertCommand.Parameters("@PostalCode").Value = Me.txtNewWZipcode.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Country").Value = Me.txtNewWCountry.Text
            If Me.chkWAddressMailing.Checked = True Then
                SqlAddressAdapter.InsertCommand.Parameters("@Mailing").Value = 1
            Else
                SqlAddressAdapter.InsertCommand.Parameters("@Mailing").Value = 0
            End If
            SqlAddressAdapter.InsertCommand.Parameters("@Process").Value = "ABR App"
            SqlAddressAdapter.InsertCommand.Parameters("@User").Value = VUser
            SqlAddressAdapter.InsertCommand.ExecuteNonQuery()
        End If

        If Me.txtNewHAddress1.Text <> "" Then
            'SqlAddressAdapter.SelectCommand = SqlInsertAddress
            SqlAddressAdapter.InsertCommand.Parameters("@ABR_ID").Value = Status.FABRID
            SqlAddressAdapter.InsertCommand.Parameters("@Type").Value = "Home"
            SqlAddressAdapter.InsertCommand.Parameters("@Address1").Value = Me.txtNewHAddress1.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Address2").Value = Me.txtNewHAddress2.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Address3").Value = Me.txtNewHAddress3.Text
            SqlAddressAdapter.InsertCommand.Parameters("@City").Value = Me.txtNewHCity.Text
            SqlAddressAdapter.InsertCommand.Parameters("@State").Value = Me.txtNewHState.Text
            SqlAddressAdapter.InsertCommand.Parameters("@PostalCode").Value = Me.txtNewHZip.Text
            SqlAddressAdapter.InsertCommand.Parameters("@Country").Value = Me.txtNewHCountry.Text
            If Me.chkHAddressMailing.Checked = True Then
                SqlAddressAdapter.InsertCommand.Parameters("@Mailing").Value = 1
            Else
                SqlAddressAdapter.InsertCommand.Parameters("@Mailing").Value = 0
            End If
            SqlAddressAdapter.InsertCommand.Parameters("@Process").Value = "ABR App"
            SqlAddressAdapter.InsertCommand.Parameters("@User").Value = VUser
            SqlAddressAdapter.InsertCommand.ExecuteNonQuery()
        End If

        If vContactUpdate = 1 Then
            'Update Current Work Contact Information as Inactive
            'Loop throught for each contact type
            'Only Update if Type populated and if Prior Type existed
            For i = 1 To 6
                Select Case i
                    Case 1         'Office
                        vContactType = "Office Phone"
                        If Me.txtNewWPhone.Text <> "" Then
                            VDetails = Me.txtNewWPhone.Text
                        Else
                            VDetails = ""
                        End If
                    Case 2         'Fax
                        vContactType = "Fax Phone"
                        If Me.txtNewWFax.Text <> "" Then
                            VDetails = Me.txtNewWFax.Text
                        Else
                            VDetails = ""
                        End If
                    Case 3         'Email
                        vContactType = "Work eMail"
                        If Me.txtNewWEMail.Text <> "" Then
                            VDetails = Me.txtNewWEMail.Text
                        Else
                            VDetails = ""
                        End If
                    Case 4         'Office
                        If Me.txtNewHPhone.Text <> "" Then
                            vContactType = "Home Phone"
                            VDetails = Me.txtNewHPhone.Text
                        Else
                            VDetails = ""
                        End If
                    Case 5         'Cell
                        If Me.txtNewHCell.Text <> "" Then
                            vContactType = "Cell Phone"
                            VDetails = Me.txtNewHCell.Text
                        Else
                            VDetails = ""
                        End If
                    Case 6         'Email
                        If Me.txtNewHEMail.Text <> "" Then
                            vContactType = "Home eMail"
                            VDetails = Me.txtNewHEMail.Text
                        Else
                            VDetails = ""
                        End If
                End Select

                ' Make sure New Values given before updating to inactive
                If VDetails <> "" Then
                    'SqlContactAdapter.SelectCommand = SqlUpdateContact
                    SqlContactAdapter.UpdateCommand.Parameters("@ABRID").Value = Status.FABRID
                    SqlContactAdapter.UpdateCommand.Parameters("@Type").Value = vContactType
                    SqlContactAdapter.UpdateCommand.Parameters("@Process").Value = "ABRApp"
                    SqlContactAdapter.UpdateCommand.Parameters("@User").Value = VUser
                    SqlContactAdapter.UpdateCommand.ExecuteNonQuery()
                End If
            Next
        End If

        'Insert New Contact Information
        'Loop throught for each contact type
        For i = 1 To 3
            Select Case i
                Case 1     'Office
                    If (Me.txtNewWPhone.Text <> "") Then
                        vContactType = "Office Phone"
                        VDetails = Me.txtNewWPhone.Text
                    Else : VDetails = ""
                    End If
                Case 2     'Fax
                    If (Me.txtNewWFax.Text <> "") Then
                        vContactType = "Fax Phone"
                        VDetails = Me.txtNewWFax.Text
                    Else : VDetails = ""
                    End If
                Case 3     'Work Email
                    If (Me.txtNewWEMail.Text <> "") Then
                        vContactType = "Work eMail"
                        VDetails = Me.txtNewWEMail.Text
                    Else : VDetails = ""
                    End If
                Case 4     'Home
                    'If the the new matches the old then details =""
                    If Me.txtNewHPhone.Text <> "" Then
                        vContactType = "Home Phone"
                        VDetails = Me.txtNewHPhone.Text
                    Else
                        VDetails = ""
                    End If
                Case 5     'Cell
                    'If the the new matches the old then details =""
                    If Me.txtNewHCell.Text <> "" Then
                        vContactType = "Cell Phone"
                        VDetails = Me.txtNewHCell.Text
                    Else
                        VDetails = ""
                    End If
                Case 6     'Home Email
                    If Me.txtNewHEMail.Text <> "" Then
                        vContactType = "Home eMail"
                        VDetails = Me.txtNewHEMail.Text
                    Else
                        VDetails = ""
                    End If
                Case Else : VDetails = ""
            End Select

            ' Make sure New Values given before updating to inactive
            If VDetails <> "" Then
                'Insert New Contact Information
                'SqlContactAdapter.SelectCommand = SqlInsertContact
                SqlContactAdapter.InsertCommand.Parameters("@ABRID").Value = Status.FABRID
                SqlContactAdapter.InsertCommand.Parameters("@Type").Value = vContactType
                SqlContactAdapter.InsertCommand.Parameters("@Details").Value = VDetails
                SqlContactAdapter.InsertCommand.Parameters("@PrimaryContact").Value = 0
                SqlContactAdapter.InsertCommand.Parameters("@Process").Value = "ABRApp"
                SqlContactAdapter.InsertCommand.Parameters("@User").Value = System.Environment.UserName
                SqlContactAdapter.InsertCommand.ExecuteNonQuery()
            End If
        Next

    End Sub
0
 
Carl TawnSystems and Integration DeveloperCommented:
Your code doesn't show where you actually create your Connection and SqlDataAdapter objects.

If you haven't already then you need create a Connection and assign it to your Commands:

    Dim conn As New SqlConnection("Your connection string")

    SqlContactAdapter.SelectCommand.ActiveConnection = conn
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now