Solved

Error  Fill: SelectCommand.Connection property has not been initialized

Posted on 2006-07-07
9
1,921 Views
Last Modified: 2012-06-27
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
Comment
Question by:TimSweet220
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17061638
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
 
LVL 2

Accepted Solution

by:
Bill_PSC earned 500 total points
ID: 17061728
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
 

Author Comment

by:TimSweet220
ID: 17061739
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:TimSweet220
ID: 17061765
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17061766
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
 
LVL 35

Expert Comment

by:YZlat
ID: 17061900
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
 

Author Comment

by:TimSweet220
ID: 17061954
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
 
LVL 35

Expert Comment

by:YZlat
ID: 17062349
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17062383
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question